- optimize autoloader

This commit is contained in:
uwetews
2015-09-14 23:02:59 +02:00
parent bfcffb009a
commit 56a884a428
5 changed files with 45 additions and 51 deletions

View File

@@ -1,10 +1,15 @@
 ===== 3.1.28-dev===== (xx.xx.2015)  ===== 3.1.28-dev===== (xx.xx.2015)
01.09.2015 14.09.2015
- optimize autoloader
30.08.2015
- size optimization move some runtime functions into extension
- optimize inline template processing
- optimization merge inheritance child and parent templates into one compiled template file
29.08.2015
- improvement convert template inheritance into runtime processing - improvement convert template inheritance into runtime processing
- bugfix {$smarty.block.parent} did always reference the root parent block https://github.com/smarty-php/smarty/issues/68 - bugfix {$smarty.block.parent} did always reference the root parent block https://github.com/smarty-php/smarty/issues/68
- move subtemplate code into runtime extension and optimize for size and speed
- move template function code into runtime extension
- remove unneeded code and properties, minor fixes
23.08.2015 23.08.2015
- introduce Smarty::$resource_cache_mode and cache template object of {include} inside loop - introduce Smarty::$resource_cache_mode and cache template object of {include} inside loop
@@ -322,8 +327,8 @@
- bugfix Debug Console did not include all data from merged compiled subtemplates - bugfix Debug Console did not include all data from merged compiled subtemplates
04.11.2014 04.11.2014
- new feature $smarty->debug = true; => overwrite existing Debug Console window (old behaviour) - new feature $smarty->debugging = true; => overwrite existing Debug Console window (old behaviour)
$smarty->debug = 2; => individual Debug Console window by template name $smarty->debugging = 2; => individual Debug Console window by template name
03.11.2014 03.11.2014
- bugfix Debug Console did not show included subtemplates since 3.1.17 (forum 25301) - bugfix Debug Console did not show included subtemplates since 3.1.17 (forum 25301)

View File

@@ -40,15 +40,6 @@ class Smarty_Autoloader
*/ */
public static $rootClasses = array('smarty' => 'Smarty.class.php', 'smartybc' => 'SmartyBC.class.php',); public static $rootClasses = array('smarty' => 'Smarty.class.php', 'smartybc' => 'SmartyBC.class.php',);
/**
* 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,);
/** /**
* Registers Smarty_Autoloader backward compatible to older installations. * Registers Smarty_Autoloader backward compatible to older installations.
* *
@@ -89,9 +80,6 @@ class Smarty_Autoloader
} else { } else {
spl_autoload_register(array(__CLASS__, 'autoload')); spl_autoload_register(array(__CLASS__, 'autoload'));
} }
foreach (self::$rootClasses as $class => $file) {
self::$classes[$class] = self::$SMARTY_DIR . $file;
}
} }
/** /**
@@ -102,28 +90,33 @@ class Smarty_Autoloader
public static function autoload($class) public static function autoload($class)
{ {
$_class = strtolower($class); $_class = strtolower($class);
if (0 !== strpos($_class, 'smarty')) { if (preg_match('/^(smarty_((internal_(compile_)?)|((template_(source|config|cache|compiled|resource_base))|((cached|compiled)?resource)|(variable|security)))|(smarty(bc)?)$)/', $_class, $match)) {
return; $file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php';
} if (!empty($match[3])) {
$file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php'; if (!empty($match[4])) {
if (0 === strpos($_class, 'smarty_internal')) { if (is_file($file)) {
if (0 === strpos($_class, 'smarty_internal_compile')) { require $file;
if (is_file($file)) { }
require_once $file; return;
} else {
@include $file;
return; return;
} }
} else { } elseif (!empty($match[5])) {
@include $file; @include $file;
return; return;
} elseif (!empty($match[11]) && isset(self::$rootClasses[$_class])) {
$file = self::$rootClasses[$_class];
require $file;
return;
} }
} }
if (isset(self::$classes[$_class])) { if (0 !== strpos($_class, 'smarty')) {
$file = self::$classes[$_class] === true ? $file : self::$classes[$_class];
require_once $file;
return; return;
} }
$file = isset($file) ? $file : self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php';
if (is_file($file)) { if (is_file($file)) {
require_once $file; require $file;
return; return;
} }
return; return;

View File

@@ -94,6 +94,7 @@ if (!class_exists('Smarty_Internal_Data', false)) {
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_templatebase.php'; require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_templatebase.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_template.php'; require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_template.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_resource.php'; require_once SMARTY_SYSPLUGINS_DIR . 'smarty_resource.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_resource_file.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_variable.php'; require_once SMARTY_SYSPLUGINS_DIR . 'smarty_variable.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_source.php'; require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_source.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_resource_base.php'; require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_resource_base.php';
@@ -118,7 +119,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/** /**
* smarty version * smarty version
*/ */
const SMARTY_VERSION = '3.1.28-dev/54'; const SMARTY_VERSION = '3.1.28-dev/55';
/** /**
* define variable scopes * define variable scopes

View File

@@ -197,9 +197,6 @@ abstract class Smarty_CacheResource
// try sysplugins dir // try sysplugins dir
if (isset(self::$sysplugins[$type])) { if (isset(self::$sysplugins[$type])) {
$cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type); $cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type);
if (!class_exists($cache_resource_class, false)) {
require SMARTY_SYSPLUGINS_DIR . self::$sysplugins[$type];
}
return $smarty->_cache['cacheresource_handlers'][$type] = new $cache_resource_class(); return $smarty->_cache['cacheresource_handlers'][$type] = new $cache_resource_class();
} }
// try plugins dir // try plugins dir

View File

@@ -35,12 +35,12 @@ abstract class Smarty_Resource
* *
* @var array * @var array
*/ */
protected static $sysplugins = array('file' => 'smarty_internal_resource_file.php', public static $sysplugins = array('file' => 'smarty_internal_resource_file.php',
'string' => 'smarty_internal_resource_string.php', 'string' => 'smarty_internal_resource_string.php',
'extends' => 'smarty_internal_resource_extends.php', 'extends' => 'smarty_internal_resource_extends.php',
'stream' => 'smarty_internal_resource_stream.php', 'stream' => 'smarty_internal_resource_stream.php',
'eval' => 'smarty_internal_resource_eval.php', 'eval' => 'smarty_internal_resource_eval.php',
'php' => 'smarty_internal_resource_php.php'); 'php' => 'smarty_internal_resource_php.php');
/** /**
* Flag if resource does implement populateCompiledFilepath() method * Flag if resource does implement populateCompiledFilepath() method
@@ -152,16 +152,14 @@ abstract class Smarty_Resource
// try registered resource // try registered resource
if (isset($smarty->registered_resources[$type])) { if (isset($smarty->registered_resources[$type])) {
return $smarty->_cache['resource_handlers'][$type] = $smarty->registered_resources[$type] instanceof return $smarty->_cache['resource_handlers'][$type] =
Smarty_Resource ? $smarty->registered_resources[$type] : new Smarty_Internal_Resource_Registered(); $smarty->registered_resources[$type] instanceof Smarty_Resource ? $smarty->registered_resources[$type] :
new Smarty_Internal_Resource_Registered();
} }
// try sysplugins dir // try sysplugins dir
if (isset(self::$sysplugins[$type])) { if (isset(self::$sysplugins[$type])) {
$_resource_class = 'Smarty_Internal_Resource_' . ucfirst($type); $_resource_class = 'Smarty_Internal_Resource_' . ucfirst($type);
if (!class_exists($_resource_class, false)) {
require SMARTY_SYSPLUGINS_DIR . self::$sysplugins[$type];
}
return $smarty->_cache['resource_handlers'][$type] = new $_resource_class(); return $smarty->_cache['resource_handlers'][$type] = new $_resource_class();
} }
@@ -171,10 +169,9 @@ abstract class Smarty_Resource
if (class_exists($_resource_class, false)) { if (class_exists($_resource_class, false)) {
return $smarty->_cache['resource_handlers'][$type] = new $_resource_class(); return $smarty->_cache['resource_handlers'][$type] = new $_resource_class();
} else { } else {
$smarty->registerResource($type, array("smarty_resource_{$type}_source", $smarty->registerResource($type,
"smarty_resource_{$type}_timestamp", array("smarty_resource_{$type}_source", "smarty_resource_{$type}_timestamp",
"smarty_resource_{$type}_secure", "smarty_resource_{$type}_secure", "smarty_resource_{$type}_trusted"));
"smarty_resource_{$type}_trusted"));
// give it another try, now that the resource is registered properly // give it another try, now that the resource is registered properly
return self::load($smarty, $type); return self::load($smarty, $type);
} }
@@ -263,7 +260,8 @@ abstract class Smarty_Resource
* *
* @return Smarty_Template_Source Source Object * @return Smarty_Template_Source Source Object
*/ */
public static function source(Smarty_Internal_Template $_template = null, Smarty $smarty = null, $template_resource = null) public static function source(Smarty_Internal_Template $_template = null, Smarty $smarty = null,
$template_resource = null)
{ {
return Smarty_Template_Source::load($_template, $smarty, $template_resource); return Smarty_Template_Source::load($_template, $smarty, $template_resource);
} }