db: use builtin classloader, lowercase class files
This commit is contained in:
parent
07be89952d
commit
57b8469e67
7 changed files with 20 additions and 21 deletions
15
include/classloader.php
Normal file
15
include/classloader.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?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;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,13 +1,9 @@
|
|||
<?php
|
||||
|
||||
require_once "config.php";
|
||||
require_once "classloader.php";
|
||||
|
||||
$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_class = 'db_'.lcfirst(DB_TYPE);
|
||||
|
||||
$db = $db_class::instance(); // call_user_func(array($db_class, 'instance'));
|
||||
|
||||
|
@ -66,4 +62,4 @@ function db_quote($str){
|
|||
return $db->quote($str);
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
@ -5,19 +5,7 @@
|
|||
$fetch_last_error = false;
|
||||
$pluginhost = false;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
require_once "classloader.php";
|
||||
|
||||
mb_internal_encoding("UTF-8");
|
||||
date_default_timezone_set('UTC');
|
||||
|
@ -3903,4 +3891,4 @@
|
|||
return in_array($interface, class_implements($class));
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
Loading…
Reference in a new issue