fix autoloader optimization

This commit is contained in:
Uwe Tews
2015-08-06 00:59:06 +02:00
parent 8c5f20430d
commit ca969fe663

View File

@@ -33,13 +33,6 @@ class Smarty_Autoloader
*/ */
public static $SMARTY_SYSPLUGINS_DIR = ''; public static $SMARTY_SYSPLUGINS_DIR = '';
/**
* Array of not existing classes to avoid is_file calls for already tested classes
*
* @var array
*/
public static $unknown = array();
/** /**
* Array with Smarty core classes and their filename * Array with Smarty core classes and their filename
* *
@@ -54,12 +47,7 @@ class Smarty_Autoloader
*/ */
private static $classes = array('smarty_config_source' => true, 'smarty_security' => true, private static $classes = array('smarty_config_source' => true, 'smarty_security' => true,
'smarty_cacheresource' => true, 'smarty_compiledresource' => true, 'smarty_cacheresource' => true, 'smarty_compiledresource' => true,
'smarty_template_config' => true, 'smarty_internal_data' => true, 'smarty_template_config' => true,);
'smarty_internal_extension_config' => true,
'smarty_internal_extension_loadplugin' => true,
'smarty_internal_extension_append' => true,
'smarty_internal_filter_handler' => true,
'smarty_internal_function_call_handler' => true,);
/** /**
* Registers Smarty_Autoloader backward compatible to older installations. * Registers Smarty_Autoloader backward compatible to older installations.
@@ -74,7 +62,9 @@ class Smarty_Autoloader
if (!defined('SMARTY_SPL_AUTOLOAD')) { if (!defined('SMARTY_SPL_AUTOLOAD')) {
define('SMARTY_SPL_AUTOLOAD', 0); define('SMARTY_SPL_AUTOLOAD', 0);
} }
if (SMARTY_SPL_AUTOLOAD && set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false) { if (SMARTY_SPL_AUTOLOAD &&
set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false
) {
$registeredAutoLoadFunctions = spl_autoload_functions(); $registeredAutoLoadFunctions = spl_autoload_functions();
if (!isset($registeredAutoLoadFunctions['spl_autoload'])) { if (!isset($registeredAutoLoadFunctions['spl_autoload'])) {
spl_autoload_register(); spl_autoload_register();
@@ -92,7 +82,8 @@ class Smarty_Autoloader
public static function register($prepend = false) public static function register($prepend = false)
{ {
self::$SMARTY_DIR = defined('SMARTY_DIR') ? SMARTY_DIR : dirname(__FILE__) . DIRECTORY_SEPARATOR; self::$SMARTY_DIR = defined('SMARTY_DIR') ? SMARTY_DIR : dirname(__FILE__) . DIRECTORY_SEPARATOR;
self::$SMARTY_SYSPLUGINS_DIR = defined('SMARTY_SYSPLUGINS_DIR') ? SMARTY_SYSPLUGINS_DIR : self::$SMARTY_DIR . 'sysplugins' . DIRECTORY_SEPARATOR; self::$SMARTY_SYSPLUGINS_DIR = defined('SMARTY_SYSPLUGINS_DIR') ? SMARTY_SYSPLUGINS_DIR : self::$SMARTY_DIR .
'sysplugins' . DIRECTORY_SEPARATOR;
if (version_compare(phpversion(), '5.3.0', '>=')) { if (version_compare(phpversion(), '5.3.0', '>=')) {
spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend); spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
} else { } else {
@@ -110,22 +101,31 @@ class Smarty_Autoloader
*/ */
public static function autoload($class) public static function autoload($class)
{ {
// Request for Smarty or already unknown class
if (isset(self::$unknown[$class])) {
return;
}
$_class = strtolower($class); $_class = strtolower($class);
if (isset(self::$classes[$_class])) { if (0 !== strpos($_class, 'smarty')) {
$file = self::$classes[$_class] === true ? self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php' : self::$classes[$_class];
require_once $file;
return; return;
} }
$file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php'; $file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php';
if (0 === strpos($_class, 'smarty_internal')) {
if (0 === strpos($_class, 'smarty_internal_compile')) {
if (is_file($file)) {
require_once $file;
return;
}
} else {
@include $file;
return;
}
}
if (isset(self::$classes[$_class])) {
$file = self::$classes[$_class] === true ? $file : self::$classes[$_class];
require_once $file;
return;
}
if (is_file($file)) { if (is_file($file)) {
require_once $file; require_once $file;
return; return;
} }
self::$unknown[$class] = true;
return; return;
} }
} }