]> git.wh0rd.org Git - tt-rss.git/commitdiff
Revert "db: use builtin classloader, lowercase class files"
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Fri, 15 Mar 2013 15:54:08 +0000 (19:54 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Fri, 15 Mar 2013 15:54:08 +0000 (19:54 +0400)
This reverts commit 57b8469e674ef082c30b7d1de40d5d53d50b251b.

classes/Db/Abstract.php [new file with mode: 0644]
classes/Db/Interface.php [new file with mode: 0644]
classes/Db/Mysql.php [new file with mode: 0644]
classes/Db/Pgsql.php [new file with mode: 0644]
classes/db/abstract.php [deleted file]
classes/db/interface.php [deleted file]
classes/db/mysql.php [deleted file]
classes/db/pgsql.php [deleted file]
include/classloader.php [deleted file]
include/db.php
include/functions.php

diff --git a/classes/Db/Abstract.php b/classes/Db/Abstract.php
new file mode 100644 (file)
index 0000000..d84701f
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+
+abstract class Db_Abstract implements Db_Interface
+{
+    private $dbconn;
+    protected static $instance;
+
+    private function __construct() { }
+
+    public static function instance()
+    {
+        if (is_null(static::$instance)) {
+            static::$instance = new static();
+        }
+
+        return static::$instance;
+    }
+
+    public function connect($host, $user, $pass, $db) { }
+
+    public function getLink()
+    {
+        return $this->dbconn;
+    }
+
+    public function init() { }
+
+    public function escape_string($s, $strip_tags = true) { }
+
+    public function query($query, $die_on_error = true) { }
+
+    public function fetch_assoc($result) { }
+
+    public function num_rows($result) { }
+
+    public function fetch_result($result, $row, $param) { }
+
+    public function unescape_string($str)
+    {
+        $tmp = str_replace("\\\"", "\"", $str);
+        $tmp = str_replace("\\'", "'", $tmp);
+        return $tmp;
+    }
+
+    public function close() { }
+
+    public function affected_rows($result) { }
+
+    public function last_error() { }
+
+    public function quote($str)
+    {
+        return("'$str'");
+    }
+
+}
\ No newline at end of file
diff --git a/classes/Db/Interface.php b/classes/Db/Interface.php
new file mode 100644 (file)
index 0000000..c5bfad5
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+
+interface Db_Interface
+{
+    public function connect($host, $user, $pass, $db);
+    public function getLink();
+    public function init();
+    public function escape_string($s, $strip_tags = true);
+    public function query($query, $die_on_error = true);
+    public function fetch_assoc($result);
+    public function num_rows($result);
+    public function fetch_result($result, $row, $param);
+    public function unescape_string($str);
+    public function close();
+    public function affected_rows($result);
+    public function last_error();
+    public function quote($str);
+}
diff --git a/classes/Db/Mysql.php b/classes/Db/Mysql.php
new file mode 100644 (file)
index 0000000..1706283
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+
+class Db_Mysql extends Db_Abstract
+{
+    public function connect($host, $user, $pass, $db)
+    {
+        $link = mysql_connect($host, $user, $pass);
+        if ($link) {
+            $result = mysql_select_db($db, $link);
+            if (!$result) {
+                die("Can't select DB: " . mysql_error($link));
+            }
+            $this->dbconn = $link;
+            return $link;
+        } else {
+            die("Unable to connect to database (as $user to $host, database $db): " . mysql_error());
+        }
+    }
+
+    public function init()
+    {
+        db_query($this->dbconn, "SET time_zone = '+0:0'");
+
+        if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
+            db_query($this->dbconn, "SET NAMES " . MYSQL_CHARSET);
+        }
+    }
+
+    public function escape_string($s, $strip_tags = true)
+    {
+        if ($strip_tags) $s = strip_tags($s);
+        return mysql_real_escape_string($s);
+    }
+
+    public function query($query, $die_on_error = true)
+    {
+        $result = mysql_query($query, $this->dbconn);
+        if (!$result) {
+            $query = htmlspecialchars($query);
+            if ($die_on_error) {
+                die("Query <i>$query</i> failed: " . ($this->dbconn ? mysql_error($this->dbconn) : "No connection"));
+            }
+        }
+        return $result;
+    }
+
+    public function fetch_assoc($result) {
+        return mysql_fetch_assoc($result);
+    }
+
+    public function num_rows($result) {
+        return mysql_num_rows($result);
+    }
+
+    public function fetch_result($result, $row, $param) {
+        // I hate incoherent naming of PHP functions
+        return mysql_result($result, $row, $param);
+    }
+
+    public function close() {
+        return mysql_close($this->dbconn);
+    }
+
+    public function affected_rows($result) {
+        return mysql_affected_rows($this->dbconn);
+    }
+
+    public function last_error() {
+        return mysql_error($this->dbconn);
+    }
+}
diff --git a/classes/Db/Pgsql.php b/classes/Db/Pgsql.php
new file mode 100644 (file)
index 0000000..39ed181
--- /dev/null
@@ -0,0 +1,80 @@
+<?php
+
+class Db_Pgsql extends Db_Abstract
+{
+    public function connect($host, $user, $pass, $db)
+    {
+        $string = "dbname=$db user=$user";
+
+        if ($pass) {
+            $string .= " password=$pass";
+        }
+
+        if ($host) {
+            $string .= " host=$host";
+        }
+
+        if (defined('DB_PORT')) {
+            $string = "$string port=" . DB_PORT;
+        }
+
+        $link = pg_connect($string);
+
+        if (!$link) {
+            die("Unable to connect to database (as $user to $host, database $db):" . pg_last_error());
+        }
+
+        $this->dbconn = $link;
+        return $link;
+    }
+
+    public function init()
+    {
+        pg_query($this->dbconn, "set client_encoding = 'UTF-8'");
+        pg_set_client_encoding("UNICODE");
+        pg_query($this->dbconn, "set datestyle = 'ISO, european'");
+        pg_query($this->dbconn, "set TIME ZONE 0");
+    }
+
+    public function escape_string($s, $strip_tags = true)
+    {
+        if ($strip_tags) $s = strip_tags($s);
+        return pg_escape_string($s);
+    }
+
+    public function query($query, $die_on_error = true)
+    {
+        $result = pg_query($this->dbconn, $query);
+        if (!$result) {
+            $query = htmlspecialchars($query); // just in case
+            if ($die_on_error) {
+                die("Query <i>$query</i> failed [$result]: " . ($this->dbconn ? pg_last_error($this->dbconn) : "No connection"));
+            }
+        }
+        return $result;
+    }
+
+    public function fetch_assoc($result) {
+        return pg_fetch_assoc($result);
+    }
+
+    public function num_rows($result) {
+        return pg_num_rows($result);
+    }
+
+    public function fetch_result($result, $row, $param) {
+        return pg_fetch_result($result, $row, $param);
+    }
+
+    public function close() {
+        return pg_close($this->dbconn);
+    }
+
+    public function affected_rows($result) {
+        return pg_affected_rows($result);
+    }
+
+    public function last_error() {
+        return pg_last_error($this->dbconn);
+    }
+}
diff --git a/classes/db/abstract.php b/classes/db/abstract.php
deleted file mode 100644 (file)
index d84701f..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-<?php
-
-abstract class Db_Abstract implements Db_Interface
-{
-    private $dbconn;
-    protected static $instance;
-
-    private function __construct() { }
-
-    public static function instance()
-    {
-        if (is_null(static::$instance)) {
-            static::$instance = new static();
-        }
-
-        return static::$instance;
-    }
-
-    public function connect($host, $user, $pass, $db) { }
-
-    public function getLink()
-    {
-        return $this->dbconn;
-    }
-
-    public function init() { }
-
-    public function escape_string($s, $strip_tags = true) { }
-
-    public function query($query, $die_on_error = true) { }
-
-    public function fetch_assoc($result) { }
-
-    public function num_rows($result) { }
-
-    public function fetch_result($result, $row, $param) { }
-
-    public function unescape_string($str)
-    {
-        $tmp = str_replace("\\\"", "\"", $str);
-        $tmp = str_replace("\\'", "'", $tmp);
-        return $tmp;
-    }
-
-    public function close() { }
-
-    public function affected_rows($result) { }
-
-    public function last_error() { }
-
-    public function quote($str)
-    {
-        return("'$str'");
-    }
-
-}
\ No newline at end of file
diff --git a/classes/db/interface.php b/classes/db/interface.php
deleted file mode 100644 (file)
index c5bfad5..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<?php
-
-interface Db_Interface
-{
-    public function connect($host, $user, $pass, $db);
-    public function getLink();
-    public function init();
-    public function escape_string($s, $strip_tags = true);
-    public function query($query, $die_on_error = true);
-    public function fetch_assoc($result);
-    public function num_rows($result);
-    public function fetch_result($result, $row, $param);
-    public function unescape_string($str);
-    public function close();
-    public function affected_rows($result);
-    public function last_error();
-    public function quote($str);
-}
diff --git a/classes/db/mysql.php b/classes/db/mysql.php
deleted file mode 100644 (file)
index 1706283..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-<?php
-
-class Db_Mysql extends Db_Abstract
-{
-    public function connect($host, $user, $pass, $db)
-    {
-        $link = mysql_connect($host, $user, $pass);
-        if ($link) {
-            $result = mysql_select_db($db, $link);
-            if (!$result) {
-                die("Can't select DB: " . mysql_error($link));
-            }
-            $this->dbconn = $link;
-            return $link;
-        } else {
-            die("Unable to connect to database (as $user to $host, database $db): " . mysql_error());
-        }
-    }
-
-    public function init()
-    {
-        db_query($this->dbconn, "SET time_zone = '+0:0'");
-
-        if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
-            db_query($this->dbconn, "SET NAMES " . MYSQL_CHARSET);
-        }
-    }
-
-    public function escape_string($s, $strip_tags = true)
-    {
-        if ($strip_tags) $s = strip_tags($s);
-        return mysql_real_escape_string($s);
-    }
-
-    public function query($query, $die_on_error = true)
-    {
-        $result = mysql_query($query, $this->dbconn);
-        if (!$result) {
-            $query = htmlspecialchars($query);
-            if ($die_on_error) {
-                die("Query <i>$query</i> failed: " . ($this->dbconn ? mysql_error($this->dbconn) : "No connection"));
-            }
-        }
-        return $result;
-    }
-
-    public function fetch_assoc($result) {
-        return mysql_fetch_assoc($result);
-    }
-
-    public function num_rows($result) {
-        return mysql_num_rows($result);
-    }
-
-    public function fetch_result($result, $row, $param) {
-        // I hate incoherent naming of PHP functions
-        return mysql_result($result, $row, $param);
-    }
-
-    public function close() {
-        return mysql_close($this->dbconn);
-    }
-
-    public function affected_rows($result) {
-        return mysql_affected_rows($this->dbconn);
-    }
-
-    public function last_error() {
-        return mysql_error($this->dbconn);
-    }
-}
diff --git a/classes/db/pgsql.php b/classes/db/pgsql.php
deleted file mode 100644 (file)
index 39ed181..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-<?php
-
-class Db_Pgsql extends Db_Abstract
-{
-    public function connect($host, $user, $pass, $db)
-    {
-        $string = "dbname=$db user=$user";
-
-        if ($pass) {
-            $string .= " password=$pass";
-        }
-
-        if ($host) {
-            $string .= " host=$host";
-        }
-
-        if (defined('DB_PORT')) {
-            $string = "$string port=" . DB_PORT;
-        }
-
-        $link = pg_connect($string);
-
-        if (!$link) {
-            die("Unable to connect to database (as $user to $host, database $db):" . pg_last_error());
-        }
-
-        $this->dbconn = $link;
-        return $link;
-    }
-
-    public function init()
-    {
-        pg_query($this->dbconn, "set client_encoding = 'UTF-8'");
-        pg_set_client_encoding("UNICODE");
-        pg_query($this->dbconn, "set datestyle = 'ISO, european'");
-        pg_query($this->dbconn, "set TIME ZONE 0");
-    }
-
-    public function escape_string($s, $strip_tags = true)
-    {
-        if ($strip_tags) $s = strip_tags($s);
-        return pg_escape_string($s);
-    }
-
-    public function query($query, $die_on_error = true)
-    {
-        $result = pg_query($this->dbconn, $query);
-        if (!$result) {
-            $query = htmlspecialchars($query); // just in case
-            if ($die_on_error) {
-                die("Query <i>$query</i> failed [$result]: " . ($this->dbconn ? pg_last_error($this->dbconn) : "No connection"));
-            }
-        }
-        return $result;
-    }
-
-    public function fetch_assoc($result) {
-        return pg_fetch_assoc($result);
-    }
-
-    public function num_rows($result) {
-        return pg_num_rows($result);
-    }
-
-    public function fetch_result($result, $row, $param) {
-        return pg_fetch_result($result, $row, $param);
-    }
-
-    public function close() {
-        return pg_close($this->dbconn);
-    }
-
-    public function affected_rows($result) {
-        return pg_affected_rows($result);
-    }
-
-    public function last_error() {
-        return pg_last_error($this->dbconn);
-    }
-}
diff --git a/include/classloader.php b/include/classloader.php
deleted file mode 100644 (file)
index 4b8b373..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<?php
-       function __autoload($class) {
-               $class_file1 = str_replace("_", "/", basename($class));   // PSR-0
-               $class_file2 = str_replace("_", "/", strtolower(basename($class)));
-
-               $file1 = dirname(__FILE__)."/../classes/$class_file1.php";
-               $file2 = dirname(__FILE__)."/../classes/$class_file2.php";
-
-               if (file_exists($file1)) {
-                       require $file1;
-               } elseif (file_exists($file2)) {
-                       require $file2;
-               }
-       }
-?>
index 020fd08a424c4b773af58b4131b1131854b2da11..28718fb02a886d8831f580adfa00f4aee319bac1 100644 (file)
@@ -1,9 +1,13 @@
 <?php
 
 require_once "config.php";
-require_once "classloader.php";
 
-$db_class = 'db_'.lcfirst(DB_TYPE);
+$db_class = 'Db_'.ucfirst(DB_TYPE);
+$db_class_file = 'classes/' . str_replace('_', '/', $db_class) . '.php';
+
+require_once "classes/Db/Interface.php";
+require_once "classes/Db/Abstract.php";
+require_once $db_class_file;
 
 $db = $db_class::instance(); //  call_user_func(array($db_class, 'instance'));
 
@@ -62,4 +66,4 @@ function db_quote($str){
     return $db->quote($str);
 }
 
-?>
+?>
\ No newline at end of file
index caea2576afcb8fde12c575803f8f92790dbdf725..4dc286eb6ec84374b4d7c3eaf61fa617784d82e3 100644 (file)
@@ -5,7 +5,19 @@
        $fetch_last_error = false;
        $pluginhost = false;
 
-       require_once "classloader.php";
+       function __autoload($class) {
+               $class_file1 = str_replace("_", "/", basename($class));   // PSR-0
+               $class_file2 = str_replace("_", "/", strtolower(basename($class)));
+
+               $file1 = dirname(__FILE__)."/../classes/$class_file1.php";
+               $file2 = dirname(__FILE__)."/../classes/$class_file2.php";
+
+               if (file_exists($file1)) {
+                       require $file1;
+               } elseif (file_exists($file2)) {
+                       require $file2;
+               }
+       }
 
        mb_internal_encoding("UTF-8");
        date_default_timezone_set('UTC');
                return in_array($interface, class_implements($class));
        }
 
-?>
+?>
\ No newline at end of file