diff options
author | Paul Arthur <paul.arthur@flowerysong.com> | 2012-04-18 00:54:54 -0400 |
---|---|---|
committer | Paul Arthur <paul.arthur@flowerysong.com> | 2012-04-18 00:54:54 -0400 |
commit | 5f2f81fa8fe4d111b3f818be84f899f74645308d (patch) | |
tree | cb7dc3b45c8490added092a205e7f661ea97af00 | |
parent | 37fc03bb48044cc6615a315b7b5240406925ee66 (diff) | |
download | ampache-5f2f81fa8fe4d111b3f818be84f899f74645308d.tar.gz ampache-5f2f81fa8fe4d111b3f818be84f899f74645308d.tar.bz2 ampache-5f2f81fa8fe4d111b3f818be84f899f74645308d.zip |
Use spl_autoload_register instead of __autoload
Might be useful in the future, __autoload is discouraged according to
the PHP documentation.
-rw-r--r-- | lib/class/core.class.php | 25 | ||||
-rw-r--r-- | lib/general.lib.php | 25 | ||||
-rw-r--r-- | lib/init-tiny.php | 5 |
3 files changed, 29 insertions, 26 deletions
diff --git a/lib/class/core.class.php b/lib/class/core.class.php index 70247060..34d8f7ba 100644 --- a/lib/class/core.class.php +++ b/lib/class/core.class.php @@ -50,6 +50,31 @@ class Core { } // construction /** + * autoload + * This function automatically loads any missing classes as they are + * needed so that we don't use a million include statements which load + * more than we need. + */ + public static function autoload($class) { + // Lowercase the class + $class = strtolower($class); + + $file = Config::get('prefix') . "/lib/class/$class.class.php"; + + // See if it exists + if (is_readable($file)) { + require $file; + if (is_callable($class . '::_auto_init')) { + $class::_auto_init(); + } + } + // Else log this as a fatal error + else { + debug_event('autoload', "'$class' not found!", 1); + } + } // autoload + + /** * form_register * This registers a form with a SID, inserts it into the session * variables and then returns a string for use in the HTML form diff --git a/lib/general.lib.php b/lib/general.lib.php index 2e8d66df..a8e4e909 100644 --- a/lib/general.lib.php +++ b/lib/general.lib.php @@ -284,29 +284,4 @@ function translate_pattern_code($code) { } // translate_pattern_code -/** - * __autoload - * This function automatically loads any missing classes as they are needed so - * that we don't use a million include statements which load more than we need. - */ -function __autoload($class) { - // Lowercase the class - $class = strtolower($class); - - $file = Config::get('prefix') . "/lib/class/$class.class.php"; - - // See if it exists - if (is_readable($file)) { - require_once $file; - if (is_callable($class . '::_auto_init')) { - call_user_func(array($class, '_auto_init')); - } - } - // Else log this as a fatal error - else { - debug_event('__autoload', "'$class' not found!",'1'); - } - -} // __autoload - ?> diff --git a/lib/init-tiny.php b/lib/init-tiny.php index ae4c70bc..7217e769 100644 --- a/lib/init-tiny.php +++ b/lib/init-tiny.php @@ -38,12 +38,15 @@ $prefix = realpath($ampache_path . "/../"); $configfile = $prefix . '/config/ampache.cfg.php'; require_once $prefix . '/lib/general.lib.php'; require_once $prefix . '/lib/class/config.class.php'; - +require_once $prefix . '/lib/class/core.class.php'; require_once $prefix . '/modules/php-gettext/gettext.inc'; // Define some base level config options Config::set('prefix', $prefix); +// Register the autoloader +spl_autoload_register(array('Core', 'autoload'), true, true); + /* Check to see if this is http or https */ |