From 0d46c175789a22a8f13f938250968bf0d0d8d50b Mon Sep 17 00:00:00 2001 From: uwetews Date: Sat, 29 Aug 2015 14:37:59 +0200 Subject: [PATCH] - rearrange internal cache --- libs/Smarty.class.php | 43 ++++++------------- libs/sysplugins/smarty_internal_data.php | 21 +++------ .../smarty_internal_templatebase.php | 7 +++ 3 files changed, 27 insertions(+), 44 deletions(-) diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 8c9cca28..8c7f084b 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -382,13 +382,6 @@ class Smarty extends Smarty_Internal_TemplateBase */ public $merge_compiled_includes = false; - /** - * template inheritance merge compiled includes - * - * @var boolean - */ - public $inheritance_merge_compiled_includes = true; - /** * force cache file creation * @@ -646,7 +639,7 @@ class Smarty extends Smarty_Internal_TemplateBase * @var int */ public $start_time = 0; - + /** * required by the compiler for BC * @@ -680,14 +673,13 @@ class Smarty extends Smarty_Internal_TemplateBase * * @var array */ - public $obsoleteProperties = array('resource_caching', 'template_resource_caching', 'direct_access_security' , '_dir_perms', '_file_perms', 'plugin_search_order'); + private static $obsoleteProperties = array('resource_caching', 'template_resource_caching', + 'direct_access_security', '_dir_perms', '_file_perms', + 'plugin_search_order'); - /** - * Extension object cache - * - * @var array - */ - public static $extObjCache = array(); + private static $accessMap = array('template_dir' => 'getTemplateDir', 'config_dir' => 'getConfigDir', + 'plugins_dir' => 'getPluginsDir', 'compile_dir' => 'getCompileDir', + 'cache_dir' => 'getCacheDir',); /**#@-*/ @@ -1074,7 +1066,7 @@ class Smarty extends Smarty_Internal_TemplateBase } $_templateId = $this->_getTemplateId($template, $cache_id, $compile_id); if (isset($this->_cache['isCached'][$_templateId])) { - $tpl = $do_clone ? clone $this->_cache['isCached'][$_templateId] : $this->_cache['isCached'][$_templateId]; + $tpl = $do_clone ? clone $this->_cache['isCached'][$_templateId] : $this->_cache['isCached'][$_templateId]; $tpl->parent = $parent; $tpl->tpl_vars = array(); $tpl->config_vars = array(); @@ -1329,13 +1321,10 @@ class Smarty extends Smarty_Internal_TemplateBase */ public function __get($name) { - $allowed = array('template_dir' => 'getTemplateDir', 'config_dir' => 'getConfigDir', - 'plugins_dir' => 'getPluginsDir', 'compile_dir' => 'getCompileDir', - 'cache_dir' => 'getCacheDir',); - if (isset($allowed[$name])) { - return $this->{$allowed[$name]}(); - } elseif (in_array($name, $this->obsoleteProperties)) { + if (isset(self::$accessMap[$name])) { + return $this->{self::$accessMap[$name]}(); + } elseif (in_array($name, self::$obsoleteProperties)) { return null; } else { trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE); @@ -1352,13 +1341,9 @@ class Smarty extends Smarty_Internal_TemplateBase */ public function __set($name, $value) { - $allowed = array('template_dir' => 'setTemplateDir', 'config_dir' => 'setConfigDir', - 'plugins_dir' => 'setPluginsDir', 'compile_dir' => 'setCompileDir', - 'cache_dir' => 'setCacheDir',); - - if (isset($allowed[$name])) { - $this->{$allowed[$name]}($value); - } elseif (in_array($name, $this->obsoleteProperties)) { + if (isset(self::$accessMap[$name])) { + $this->{self::$accessMap[$name]}($value); + } elseif (in_array($name, self::$obsoleteProperties)) { return; } else { if (is_object($value) && method_exists($value, $name)) { diff --git a/libs/sysplugins/smarty_internal_data.php b/libs/sysplugins/smarty_internal_data.php index 9c780bc5..6d849e3c 100644 --- a/libs/sysplugins/smarty_internal_data.php +++ b/libs/sysplugins/smarty_internal_data.php @@ -53,13 +53,6 @@ class Smarty_Internal_Data */ public $config_vars = array(); - /** - * universal cache - * - * @var array() - */ - public $_cache = array(); - /** * Cache for property information from generic getter/setter * Preloaded with names which should not use with generic getter/setter @@ -336,24 +329,22 @@ class Smarty_Internal_Data */ public function __call($name, $args) { - static $_resolved_property_name = array(); - - if (!isset(Smarty::$extObjCache[$name])) { + $smarty = $this->_objType == 1 ? $this : $this->smarty; + if (!isset($smarty->_cache['extObjCache'][$name])) { $class = 'Smarty_Internal_Method_' . ucfirst($name); if (preg_match('/^(set|get)([A-Z].*)$/', $name, $match)) { if (!isset($this->_property_info[$prop = $match[2]])) { - $smarty = isset($this->smarty) ? $this->smarty : $this; if (!isset($this->_property_info[$prop])) { // convert camel case to underscored name - $_resolved_property_name[$prop] = $pn = strtolower(join('_', preg_split('/([A-Z][^A-Z]*)/', $prop, - 1, PREG_SPLIT_NO_EMPTY | + $smarty->_cache['resolvedProp'][$prop] = $pn = strtolower(join('_', preg_split('/([A-Z][^A-Z]*)/', $prop, - 1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE))); $this->_property_info[$prop] = property_exists($this, $pn) ? 1 : ($this->_objType == 2 && property_exists($smarty, $pn) ? 2 : 0); } } if ($this->_property_info[$prop]) { - $pn = $_resolved_property_name[$prop]; + $pn = $smarty->_cache['resolvedProp'][$prop]; if ($match[1] == 'get') { return $this->_property_info[$prop] == 1 ? $this->$pn : $this->smarty->$pn; } else { @@ -365,10 +356,10 @@ class Smarty_Internal_Data } } if (class_exists($class)) { - $callback = array(Smarty::$extObjCache[$name] = new $class(), $name); + $callback = array($smarty->_cache['extObjCache'][$name] = new $class(), $name); } } else { - $callback = array(Smarty::$extObjCache[$name], $name); + $callback = array($smarty->_cache['extObjCache'][$name], $name); } if (isset($callback) && $callback[0]->objMap | $this->_objType) { array_unshift($args, $this); diff --git a/libs/sysplugins/smarty_internal_templatebase.php b/libs/sysplugins/smarty_internal_templatebase.php index 7e22efea..24771d8c 100644 --- a/libs/sysplugins/smarty_internal_templatebase.php +++ b/libs/sysplugins/smarty_internal_templatebase.php @@ -74,6 +74,13 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data */ public $cache_lifetime = 3600; + /** + * universal cache + * + * @var array() + */ + public $_cache = array(); + /** * fetches a rendered Smarty template *