diff --git a/change_log.txt b/change_log.txt index 0ab106f7..b47ea29b 100644 --- a/change_log.txt +++ b/change_log.txt @@ -9,6 +9,7 @@ - remove not really needed properties - optimize rendering - move caching to Smarty::_cache + - remove properties with redundant content 06.08.2015 - avoid possible circular object references caused by parser/lexer objects diff --git a/libs/sysplugins/smarty_internal_compile_include.php b/libs/sysplugins/smarty_internal_compile_include.php index 8114a0ff..4bdaaed4 100644 --- a/libs/sysplugins/smarty_internal_compile_include.php +++ b/libs/sysplugins/smarty_internal_compile_include.php @@ -119,7 +119,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase // flag if included template code should be merged into caller $merge_compiled_includes = ($compiler->smarty->merge_compiled_includes || ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes) || - $_attr['inline'] === true) && !$compiler->template->source->recompiled; + $_attr['inline'] === true) && !$compiler->template->source->handler->recompiled; if ($merge_compiled_includes && $_attr['inline'] !== true) { // variable template name ? @@ -215,7 +215,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase if (!isset($compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid])) { $compiler->smarty->allow_ambiguous_resources = true; $tpl = new $compiler->smarty->template_class ($tpl_name, $compiler->smarty, $compiler->template, $compiler->template->cache_id, $c_id, $_caching); - if (!($tpl->source->uncompiled) && $tpl->source->exists) { + if (!($tpl->source->handler->uncompiled) && $tpl->source->exists) { $tpl->compiled = new Smarty_Template_Compiled(); $tpl->compiled->nocache_hash = $compiler->parent_compiler->template->compiled->nocache_hash; $tpl->loadCompiler(); diff --git a/libs/sysplugins/smarty_internal_method_mustcompile.php b/libs/sysplugins/smarty_internal_method_mustcompile.php index c0922e4e..7766a75e 100644 --- a/libs/sysplugins/smarty_internal_method_mustcompile.php +++ b/libs/sysplugins/smarty_internal_method_mustcompile.php @@ -31,7 +31,7 @@ class Smarty_Internal_Method_MustCompile public function mustCompile(Smarty_Internal_Template $_template) { if (!$_template->source->exists) { - if ($_template->parent instanceof Smarty_Internal_Template) { + if ($_template->parent->_objType == 2) { $parent_resource = " in '$_template->parent->template_resource}'"; } else { $parent_resource = ''; @@ -39,8 +39,8 @@ class Smarty_Internal_Method_MustCompile throw new SmartyException("Unable to load template {$_template->source->type} '{$_template->source->name}'{$parent_resource}"); } if ($_template->mustCompile === null) { - $_template->mustCompile = (!$_template->source->uncompiled && - ($_template->smarty->force_compile || $_template->source->recompiled || !$_template->compiled->exists || + $_template->mustCompile = (!$_template->source->handler->uncompiled && + ($_template->smarty->force_compile || $_template->source->handler->recompiled || !$_template->compiled->exists || ($_template->smarty->compile_check && $_template->compiled->getTimeStamp() < $_template->source->getTimeStamp()))); } diff --git a/libs/sysplugins/smarty_internal_method_registerdefaulttemplatehandler.php b/libs/sysplugins/smarty_internal_method_registerdefaulttemplatehandler.php index cbb6b1f7..40979e7a 100644 --- a/libs/sysplugins/smarty_internal_method_registerdefaulttemplatehandler.php +++ b/libs/sysplugins/smarty_internal_method_registerdefaulttemplatehandler.php @@ -65,7 +65,7 @@ class Smarty_Internal_Method_RegisterDefaultTemplateHandler $source->content = $_content; $source->timestamp = $_timestamp; $source->exists = true; - $source->recompiled = true; + $source->handler->recompiled = true; $source->filepath = false; } } diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index 423ac67a..39b8d868 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -228,7 +228,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase } } $content = null; - if ((!$this->caching || $this->cached->has_nocache_code || $this->source->recompiled) && !$no_output_filter && + if ((!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled) && !$no_output_filter && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output'])) ) { $content = Smarty_Internal_Filter_Handler::runFilter('output', ob_get_clean(), $this); @@ -390,9 +390,9 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase $_templateId = $this->smarty->_getTemplateId($template, $cache_id, $compile_id); // already in template cache? /* @var Smarty_Internal_Template $tpl */ - if (isset($this->smarty->template_objects[$_templateId])) { + if (isset($this->smarty->_cache['template_objects'][$_templateId])) { // clone cached template object because of possible recursive call - $tpl = clone $this->smarty->template_objects[$_templateId]; + $tpl = clone $this->smarty->_cache['template_objects'][$_templateId]; $tpl->parent = $this; if ((bool) $tpl->caching !== (bool) $caching) { unset($tpl->compiled); @@ -752,10 +752,10 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase */ public function loadCompiler() { - if (!class_exists($this->source->compiler_class)) { - $this->smarty->loadPlugin($this->source->compiler_class); + if (!class_exists($this->source->handler->compiler_class)) { + $this->smarty->loadPlugin($this->source->handler->compiler_class); } - $this->compiler = new $this->source->compiler_class($this->source->template_lexer_class, $this->source->template_parser_class, $this->smarty); + $this->compiler = new $this->source->handler->compiler_class($this->source->handler->template_lexer_class, $this->source->handler->template_parser_class, $this->smarty); } /** diff --git a/libs/sysplugins/smarty_template_cached.php b/libs/sysplugins/smarty_template_cached.php index 38e30653..945af42c 100644 --- a/libs/sysplugins/smarty_template_cached.php +++ b/libs/sysplugins/smarty_template_cached.php @@ -99,7 +99,7 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base $_template->cached->handler->populate($_template->cached, $_template); // caching enabled ? if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || - $_template->caching == Smarty::CACHING_LIFETIME_SAVED) || $_template->source->recompiled + $_template->caching == Smarty::CACHING_LIFETIME_SAVED) || $_template->source->handler->recompiled ) { $_template->cached->valid = false; } @@ -265,7 +265,7 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base */ public function write(Smarty_Internal_Template $_template, $content) { - if (!$_template->source->recompiled) { + if (!$_template->source->handler->recompiled) { if ($this->handler->writeCachedContent($_template, $content)) { $this->content = null; $this->timestamp = time(); @@ -298,7 +298,7 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base */ public function read(Smarty_Internal_Template $_template) { - if (!$_template->source->recompiled) { + if (!$_template->source->handler->recompiled) { return $this->handler->readCachedContent($_template); } return false; @@ -359,7 +359,7 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base */ public function writeCachedContent(Smarty_Internal_Template $_template, $content) { - if ($_template->source->recompiled || !($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || + if ($_template->source->handler->recompiled || !($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || $_template->caching == Smarty::CACHING_LIFETIME_SAVED) ) { // don't write cache file diff --git a/libs/sysplugins/smarty_template_compiled.php b/libs/sysplugins/smarty_template_compiled.php index 74e5a28b..f56190d8 100644 --- a/libs/sysplugins/smarty_template_compiled.php +++ b/libs/sysplugins/smarty_template_compiled.php @@ -36,7 +36,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base static function load($_template) { // check runtime cache - if (!$_template->source->recompiled && ($_template->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)) { + if (!$_template->source->handler->recompiled && ($_template->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)) { $_cache_key = $_template->source->unique_resource . '#'; if ($_template->caching) { $_cache_key .= 'caching#'; @@ -53,7 +53,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base $compiled->populateCompiledFilepath($_template); } // runtime cache - if (!$_template->source->recompiled && ($_template->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)) { + if (!$_template->source->handler->recompiled && ($_template->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)) { $_template->source->compileds[$_cache_key] = $compiled; } return $compiled; @@ -119,14 +119,14 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base public function process(Smarty_Internal_Template $_template) { $_smarty_tpl = $_template; - if ($_template->source->recompiled || !$_template->compiled->exists || $_template->smarty->force_compile || + if ($_template->source->handler->recompiled || !$_template->compiled->exists || $_template->smarty->force_compile || ($_template->smarty->compile_check && $_template->source->getTimeStamp() > $_template->compiled->getTimeStamp()) ) { $this->compileTemplateSource($_template); $compileCheck = $_template->smarty->compile_check; $_template->smarty->compile_check = false; - if ($_template->source->recompiled) { + if ($_template->source->handler->recompiled) { $level = ob_get_level(); ob_start(); try { @@ -236,7 +236,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base $this->nocache_hash = null; $this->unifunc = null; // compile locking - if (!$_template->source->recompiled) { + if (!$_template->source->handler->recompiled) { if ($saved_timestamp = $_template->compiled->getTimeStamp()) { touch($_template->compiled->filepath); } @@ -248,7 +248,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base } catch (Exception $e) { // restore old timestamp in case of error - if (!$_template->source->recompiled && $saved_timestamp) { + if (!$_template->source->handler->recompiled && $saved_timestamp) { touch($_template->compiled->filepath, $saved_timestamp); } throw $e; @@ -274,7 +274,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base */ public function write(Smarty_Internal_Template $_template, $code) { - if (!$_template->source->recompiled) { + if (!$_template->source->handler->recompiled) { $obj = new Smarty_Internal_Write_File(); if ($obj->writeFile($this->filepath, $code, $_template->smarty) === true) { $this->timestamp = $this->exists = is_file($this->filepath); @@ -301,7 +301,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base */ public function read(Smarty_Internal_Template $_template) { - if (!$_template->source->recompiled) { + if (!$_template->source->handler->recompiled) { return file_get_contents($this->filepath); } return isset($this->content) ? $this->content : false; diff --git a/libs/sysplugins/smarty_template_config.php b/libs/sysplugins/smarty_template_config.php index 73ef7c18..f0fff508 100644 --- a/libs/sysplugins/smarty_template_config.php +++ b/libs/sysplugins/smarty_template_config.php @@ -18,27 +18,6 @@ */ class Smarty_Template_Config extends Smarty_Template_Source { - /** - * Name of the Class to compile this resource's contents with - * - * @var string - */ - public $compiler_class = 'Smarty_Internal_Config_File_Compiler'; - - /** - * Name of the Class to tokenize this resource's contents with - * - * @var string - */ - public $template_lexer_class = 'Smarty_Internal_Configfilelexer'; - - /** - * Name of the Class to parse this resource's contents with - * - * @var string - */ - public $template_parser_class = 'Smarty_Internal_Configfileparser'; - /** * array of section names, single section or null * @@ -71,7 +50,11 @@ class Smarty_Template_Config extends Smarty_Template_Source */ public function __construct(Smarty_Resource $handler, Smarty $smarty, $resource, $type, $name) { - $this->handler = $handler; // Note: prone to circular references + // must clone handler as we change class names + $this->handler = clone $handler; // Note: prone to circular references + $this->handler->compiler_class = 'Smarty_Internal_Config_File_Compiler'; + $this->handler->template_lexer_class = 'Smarty_Internal_Configfilelexer'; + $this->handler->template_parser_class = 'Smarty_Internal_Configfileparser'; $this->resource = $resource; $this->type = $type; $this->name = $name; diff --git a/libs/sysplugins/smarty_template_source.php b/libs/sysplugins/smarty_template_source.php index f70dd256..833ce118 100644 --- a/libs/sysplugins/smarty_template_source.php +++ b/libs/sysplugins/smarty_template_source.php @@ -11,27 +11,6 @@ */ class Smarty_Template_Source { - /** - * Name of the Class to compile this resource's contents with - * - * @var string - */ - public $compiler_class = null; - - /** - * Name of the Class to tokenize this resource's contents with - * - * @var string - */ - public $template_lexer_class = null; - - /** - * Name of the Class to parse this resource's contents with - * - * @var string - */ - public $template_parser_class = null; - /** * Unique Template ID * @@ -123,20 +102,6 @@ class Smarty_Template_Source */ public $isConfig = false; - /** - * Source is bypassing compiler - * - * @var boolean - */ - public $uncompiled = false; - - /** - * Source must be recompiled on every occasion - * - * @var boolean - */ - public $recompiled = false; - /** * cache for Smarty_Template_Compiled instances * @@ -165,13 +130,6 @@ class Smarty_Template_Source public function __construct(Smarty_Resource $handler, Smarty $smarty, $resource, $type, $name) { $this->handler = $handler; // Note: prone to circular references - - $this->recompiled = $handler->recompiled; - $this->uncompiled = $handler->uncompiled; - $this->compiler_class = $handler->compiler_class; - $this->template_lexer_class = $handler->template_lexer_class; - $this->template_parser_class = $handler->template_parser_class; - $this->smarty = $smarty; $this->resource = $resource; $this->type = $type;