diff --git a/change_log.txt b/change_log.txt index 6ffee78e..440829fe 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,6 +1,7 @@  ===== 3.1.22-dev ===== (xx.xx.2015) 07.05.2015 - improvement of the debugging console. Read NEW_FEATURES.txt + - optimization of resource class loading 06.05.2015 - bugfix in 3.1.22-dev cache resource must not be loaded for subtemplates diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 98e99abc..e87f6d8d 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.22-dev/29'; + const SMARTY_VERSION = '3.1.22-dev/30'; /** * define variable scopes diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index f2f42372..1f1a81ea 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -226,7 +226,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase $isCacheTpl = $this->caching == Smarty::CACHING_LIFETIME_CURRENT || $this->caching == Smarty::CACHING_LIFETIME_SAVED; if ($isCacheTpl) { if (!isset($this->cached)) { - $this->cached = Smarty_Template_Cached::load($this); + $this->loadCached(); } $this->cached->isCached($this, true); } @@ -241,7 +241,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase if (!$this->source->uncompiled) { // render compiled code if (!isset($this->compiled)) { - $this->compiled = Smarty_Template_Compiled::load($this); + $this->loadCompiled(); } $content = $this->compiled->render($this); } else { @@ -790,6 +790,45 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase } } + /** + * Load compiled object + * + */ + public function loadCompiled() + { + if (!isset($this->compiled)) { + if (!class_exists('Smarty_Template_Compiled', false)) { + require SMARTY_SYSPLUGINS_DIR . 'smarty_template_compiled.php'; + } + $this->compiled = Smarty_Template_Compiled::load($this); + } + } + + /** + * Load cached object + * + */ + public function loadCached() + { + if (!isset($this->cached)) { + if (!class_exists('Smarty_Template_Cached', false)) { + require SMARTY_SYSPLUGINS_DIR . 'smarty_template_cached.php'; + } + $this->cached = Smarty_Template_Cached::load($this); + } + } + + /** + * Load compiler object + * + * @throws \SmartyException + */ + public function loadCompiler() + { + $this->smarty->loadPlugin($this->source->compiler_class); + $this->compiler = new $this->source->compiler_class($this->source->template_lexer_class, $this->source->template_parser_class, $this->smarty); + } + /** * Handle unknown class methods * @@ -824,18 +863,14 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase case 'cached': case 'compiler': $this->$property_name = $value; - return; - - // FIXME: routing of template -> smarty attributes default: + // Smarty property ? if (property_exists($this->smarty, $property_name)) { $this->smarty->$property_name = $value; - return; } } - throw new SmartyException("invalid template property '$property_name'."); } @@ -855,26 +890,22 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase return $this->source; case 'compiled': - $this->compiled = Smarty_Template_Compiled::load($this); + $this->loadCompiled(); return $this->compiled; case 'cached': - $this->cached = Smarty_Template_Cached::load($this); + $this->loadCached(); return $this->cached; case 'compiler': - $this->smarty->loadPlugin($this->source->compiler_class); - $this->compiler = new $this->source->compiler_class($this->source->template_lexer_class, $this->source->template_parser_class, $this->smarty); - + $this->loadCompiler(); return $this->compiler; - - // FIXME: routing of template -> smarty attributes - default: + default: + // Smarty property ? if (property_exists($this->smarty, $property_name)) { return $this->smarty->$property_name; } } - throw new SmartyException("template property '$property_name' does not exist."); } diff --git a/libs/sysplugins/smarty_internal_templatebase.php b/libs/sysplugins/smarty_internal_templatebase.php index b629aedc..68fd4be2 100644 --- a/libs/sysplugins/smarty_internal_templatebase.php +++ b/libs/sysplugins/smarty_internal_templatebase.php @@ -67,6 +67,9 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data } } // return cache status of template + if (!isset($template->cached)) { + $template->loadCached(); + } return $template->cached->isCached($template); } diff --git a/libs/sysplugins/smarty_template_cached.php b/libs/sysplugins/smarty_template_cached.php index ae8a329a..44af74c1 100644 --- a/libs/sysplugins/smarty_template_cached.php +++ b/libs/sysplugins/smarty_template_cached.php @@ -109,7 +109,13 @@ class Smarty_Template_Cached { $this->compile_id = $_template->compile_id; $this->cache_id = $_template->cache_id; + if (!isset($_template->source)) { + $_template->loadSource(); + } $this->source = $_template->source; + if (!class_exists('Smarty_CacheResource', false)) { + require SMARTY_SYSPLUGINS_DIR . 'smarty_cacheresource.php'; + } $this->handler = Smarty_CacheResource::load($_template->smarty); } diff --git a/libs/sysplugins/smarty_template_compiled.php b/libs/sysplugins/smarty_template_compiled.php index 8776a091..8147ac0b 100644 --- a/libs/sysplugins/smarty_template_compiled.php +++ b/libs/sysplugins/smarty_template_compiled.php @@ -62,6 +62,9 @@ class Smarty_Template_Compiled */ static function load($_template) { + if (!isset($_template->source)) { + $_template->loadSource(); + } // check runtime cache if (!$_template->source->recompiled && $_template->smarty->resource_caching) { $_cache_key = $_template->source->unique_resource . '#';