- optimize autoloader

This commit is contained in:
Uwe Tews
2015-06-28 08:33:18 +02:00
parent ce0c1dcfae
commit c1ae1a52af
3 changed files with 25 additions and 57 deletions

View File

@@ -6,6 +6,7 @@
- move $smarty->getTemplateVars() into extension
- move getStreamVariable() into extension
- move $smarty->append() and $smarty->appendByRef() into extension
- optimize autoloader
27.06.2015
- bugfix resolve naming conflict between custom Smarty delimiter '<%' and PHP ASP tags https://github.com/smarty-php/smarty/issues/64

View File

@@ -45,48 +45,21 @@ class Smarty_Autoloader
*
* @var array
*/
public static $rootClasses = array('Smarty' => 'Smarty.class.php', 'SmartyBC' => 'SmartyBC.class.php',);
public static $rootClasses = array('smarty' => 'Smarty.class.php', 'smartybc' => 'SmartyBC.class.php',);
private static $syspluginsClasses = array('smarty_config_source' => true,
'smarty_security' => true,
'smarty_cacheresource' => true,
'smarty_compiledresource' => true,
'smarty_cacheresource_custom' => true,
'smarty_cacheresource_keyvaluestore' => true,
'smarty_resource' => true,
'smarty_resource_custom' => true,
'smarty_resource_uncompiled' => true,
'smarty_resource_recompiled' => true,
'smarty_template_source' => true,
'smarty_template_compiled' => true,
'smarty_template_cached' => true,
'smarty_template_config' => true,
'smarty_data' => true,
'smarty_variable' => true,
'smarty_undefined_variable' => true,
'smartyexception' => true,
'smartycompilerexception' => true,
'smarty_internal_data' => true,
'smarty_internal_template' => true,
'smarty_internal_templatebase' => true,
'smarty_internal_resource_file' => true,
'smarty_internal_resource_extends' => true,
'smarty_internal_resource_eval' => true,
'smarty_internal_resource_string' => true,
'smarty_internal_resource_registered' => true,
'smarty_internal_extension_codeframe' => true,
/**
* Array of often auto loaded classes which may skip is_file() test
*
* @var array
*/
private static $classes = array('smarty_config_source' => true, 'smarty_security' => true,
'smarty_cacheresource' => true, 'smarty_compiledresource' => true,
'smarty_template_config' => true, 'smarty_internal_data' => true,
'smarty_internal_extension_config' => true,
'smarty_internal_extension_filter' => true,
'smarty_internal_extension_autoloadfilter' => true,
'smarty_internal_extension_object' => true,
'smarty_internal_extension_loadplugin' => true,
'smarty_internal_extension_clearcompiled' => true,
'smarty_internal_extension_getvars' => true,
'smarty_internal_extension_append' => true,
'smarty_internal_filter_handler' => true,
'smarty_internal_function_call_handler' => true,
'smarty_internal_cacheresource_file' => true,
'smarty_internal_write_file' => true,);
'smarty_internal_function_call_handler' => true,);
/**
* Registers Smarty_Autoloader backward compatible to older installations.
@@ -101,7 +74,7 @@ class Smarty_Autoloader
if (!defined('SMARTY_SPL_AUTOLOAD')) {
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() . DIRECTORY_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false) {
$registeredAutoLoadFunctions = spl_autoload_functions();
if (!isset($registeredAutoLoadFunctions['spl_autoload'])) {
spl_autoload_register();
@@ -118,17 +91,20 @@ class Smarty_Autoloader
*/
public static function register($prepend = false)
{
self::$SMARTY_DIR = defined('SMARTY_DIR') ? SMARTY_DIR : dirname(__FILE__) . '/';
self::$SMARTY_SYSPLUGINS_DIR = defined('SMARTY_SYSPLUGINS_DIR') ? SMARTY_SYSPLUGINS_DIR : self::$SMARTY_DIR . 'sysplugins/';
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;
if (version_compare(phpversion(), '5.3.0', '>=')) {
spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
} else {
spl_autoload_register(array(__CLASS__, 'autoload'));
}
foreach (self::$rootClasses as $class => $file) {
self::$classes[$class] = self::$SMARTY_DIR . $file;
}
}
/**
* Handles autoloading of classes.
* Handles auto loading of classes.
*
* @param string $class A class name.
*/
@@ -139,19 +115,10 @@ class Smarty_Autoloader
return;
}
$_class = strtolower($class);
if (isset(self::$syspluginsClasses[$_class])) {
$_class = (self::$syspluginsClasses[$_class] === true) ? $_class : self::$syspluginsClasses[$_class];
$file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php';
if (isset(self::$classes[$_class])) {
$file = self::$classes[$_class] === true ? self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php' : self::$classes[$_class];
require_once $file;
return;
} elseif (0 !== strpos($_class, 'smarty_internal_')) {
if (isset(self::$rootClasses[$class])) {
$file = self::$SMARTY_DIR . self::$rootClasses[$class];
require_once $file;
return;
}
self::$unknown[$class] = true;
return;
}
$file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php';
if (is_file($file)) {

View File

@@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
const SMARTY_VERSION = '3.1.28-dev/16';
const SMARTY_VERSION = '3.1.28-dev/17';
/**
* define variable scopes