diff --git a/change_log.txt b/change_log.txt index 2c401a20..7f1e5d66 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@  ===== 3.1.30-dev ===== (xx.xx.xx) + 23.12.2015 + - optimization move internal method decodeProperties back into template object + 22.12.2015 - change $xxx_dir properties from private to protected in case Smarty class gets extended - code optimizations diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 0f474f1f..4abcb888 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -118,7 +118,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.30-dev/5'; + const SMARTY_VERSION = '3.1.30-dev/6'; /** * define variable scopes diff --git a/libs/sysplugins/smarty_internal_extension_handler.php b/libs/sysplugins/smarty_internal_extension_handler.php index 68012d86..adcbaef2 100644 --- a/libs/sysplugins/smarty_internal_extension_handler.php +++ b/libs/sysplugins/smarty_internal_extension_handler.php @@ -14,16 +14,13 @@ * @property Smarty_Internal_Runtime_SubTemplate $_subTemplate * @property Smarty_Internal_Runtime_TplFunction $_tplFunction * @property Smarty_Internal_Runtime_Var $_var - * @property Smarty_Internal_Runtime_Config $_config * @property Smarty_Internal_Runtime_Foreach $_foreach * @property Smarty_Internal_Runtime_Hhvm $_hhvm * @property Smarty_Internal_Runtime_WriteFile $_writeFile - * @property Smarty_Internal_Runtime_ValidateCompiled $_validateCompiled * @property Smarty_Internal_Runtime_CodeFrame $_codeFrame * @property Smarty_Internal_Runtime_FilterHandler $_filterHandler * @property Smarty_Internal_Runtime_GetIncludePath $_getIncludePath * @property Smarty_Internal_Runtime_UpdateScope $_updateScope - * @property Smarty_Internal_Runtime_IsCached $_isCached * @property Smarty_Internal_Runtime_CacheModify $_cacheModify * @property Smarty_Internal_Runtime_UpdateCache $_updateCache * @property Smarty_Internal_Method_GetTemplateVars $getTemplateVars diff --git a/libs/sysplugins/smarty_internal_runtime_codeframe.php b/libs/sysplugins/smarty_internal_runtime_codeframe.php index ce674977..a3ef052e 100644 --- a/libs/sysplugins/smarty_internal_runtime_codeframe.php +++ b/libs/sysplugins/smarty_internal_runtime_codeframe.php @@ -18,9 +18,9 @@ class Smarty_Internal_Runtime_CodeFrame * Create code frame for compiled and cached templates * * @param Smarty_Internal_Template $_template - * @param string $content optional template content + * @param string $content optional template content * @param string $functions compiled template function and block code - * @param bool $cache flag for cache file + * @param bool $cache flag for cache file * @param \Smarty_Internal_TemplateCompilerBase $compiler * * @return string @@ -49,8 +49,8 @@ class Smarty_Internal_Runtime_CodeFrame $output .= "/* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n from \"" . $_template->source->filepath . "\" */\n\n"; - $dec = "\$_smarty_tpl->smarty->ext->_validateCompiled->decodeProperties(\$_smarty_tpl, " . - var_export($properties, true) . ',' . ($cache ? 'true' : 'false') . ")"; + $dec = "\$_smarty_tpl->_decodeProperties(\$_smarty_tpl, " . var_export($properties, true) . ',' . + ($cache ? 'true' : 'false') . ")"; $output .= "if ({$dec}) {\n"; $output .= "function {$properties['unifunc']} (\$_smarty_tpl) {\n"; // include code for plugins diff --git a/libs/sysplugins/smarty_internal_runtime_validatecompiled.php b/libs/sysplugins/smarty_internal_runtime_validatecompiled.php deleted file mode 100644 index 7defd6c9..00000000 --- a/libs/sysplugins/smarty_internal_runtime_validatecompiled.php +++ /dev/null @@ -1,86 +0,0 @@ -smarty->compile_check) || $tpl->smarty->compile_check == 1) - ) { - // check file dependencies at compiled code - foreach ($properties['file_dependency'] as $_file_to_check) { - if ($_file_to_check[2] == 'file' || $_file_to_check[2] == 'extends' || $_file_to_check[2] == 'php') { - if ($tpl->source->filepath == $_file_to_check[0]) { - // do not recheck current template - continue; - //$mtime = $tpl->source->getTimeStamp(); - } else { - // file and php types can be checked without loading the respective resource handlers - $mtime = is_file($_file_to_check[0]) ? filemtime($_file_to_check[0]) : false; - } - } elseif ($_file_to_check[2] == 'string') { - continue; - } else { - $handler = Smarty_Resource::load($tpl->smarty, $_file_to_check[2]); - if ($handler->checkTimestamps()) { - $source = Smarty_Template_Source::load($tpl, $tpl->smarty, $_file_to_check[ 0 ]); - $mtime = $source->getTimeStamp(); - } else { - continue; - } - } - if (!$mtime || $mtime > $_file_to_check[1]) { - $is_valid = false; - break; - } - } - } - if ($cache) { - // CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc - if ($tpl->caching === Smarty::CACHING_LIFETIME_SAVED && $properties['cache_lifetime'] >= 0 && - (time() > ($tpl->cached->timestamp + $properties['cache_lifetime'])) - ) { - $is_valid = false; - } - $tpl->cached->cache_lifetime = $properties['cache_lifetime']; - $tpl->cached->valid = $is_valid; - $resource = $tpl->cached; - } else { - $tpl->mustCompile = !$is_valid; - $resource = $tpl->compiled; - $resource->includes = isset($properties['includes']) ? $properties['includes'] : array(); - } - if ($is_valid) { - $resource->unifunc = $properties['unifunc']; - $resource->has_nocache_code = $properties['has_nocache_code']; - // $tpl->compiled->nocache_hash = $properties['nocache_hash']; - $resource->file_dependency = $properties['file_dependency']; - if (isset($properties['tpl_function'])) { - $tpl->tpl_function = $properties['tpl_function']; - } - } - return $is_valid && !function_exists($properties['unifunc']); - } -} diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index 7c16a53d..ea8576c8 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -211,6 +211,81 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase } } + /** + * This function is executed automatically when a compiled or cached template file is included + * - Decode saved properties from compiled template and cache files + * - Check if compiled or cache file is valid + * + * @param array $properties special template properties + * @param bool $cache flag if called from cache file + * + * @return bool flag if compiled or cache file is valid + */ + public function _decodeProperties(Smarty_Internal_Template $tpl, $properties, $cache = false) + { + $is_valid = true; + if (Smarty::SMARTY_VERSION != $properties['version']) { + // new version must rebuild + $is_valid = false; + } elseif ($is_valid && !empty($properties['file_dependency']) && + ((!$cache && $tpl->smarty->compile_check) || $tpl->smarty->compile_check == 1) + ) { + // check file dependencies at compiled code + foreach ($properties['file_dependency'] as $_file_to_check) { + if ($_file_to_check[2] == 'file' || $_file_to_check[2] == 'extends' || $_file_to_check[2] == 'php') { + if ($tpl->source->filepath == $_file_to_check[0]) { + // do not recheck current template + continue; + //$mtime = $tpl->source->getTimeStamp(); + } else { + // file and php types can be checked without loading the respective resource handlers + $mtime = is_file($_file_to_check[0]) ? filemtime($_file_to_check[0]) : false; + } + } elseif ($_file_to_check[2] == 'string') { + continue; + } else { + $handler = Smarty_Resource::load($tpl->smarty, $_file_to_check[2]); + if ($handler->checkTimestamps()) { + $source = Smarty_Template_Source::load($tpl, $tpl->smarty, $_file_to_check[ 0 ]); + $mtime = $source->getTimeStamp(); + } else { + continue; + } + } + if (!$mtime || $mtime > $_file_to_check[1]) { + $is_valid = false; + break; + } + } + } + if ($cache) { + // CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc + if ($tpl->caching === Smarty::CACHING_LIFETIME_SAVED && $properties['cache_lifetime'] >= 0 && + (time() > ($tpl->cached->timestamp + $properties['cache_lifetime'])) + ) { + $is_valid = false; + } + $tpl->cached->cache_lifetime = $properties['cache_lifetime']; + $tpl->cached->valid = $is_valid; + $resource = $tpl->cached; + } else { + $tpl->mustCompile = !$is_valid; + $resource = $tpl->compiled; + $resource->includes = isset($properties['includes']) ? $properties['includes'] : array(); + } + if ($is_valid) { + $resource->unifunc = $properties['unifunc']; + $resource->has_nocache_code = $properties['has_nocache_code']; + // $tpl->compiled->nocache_hash = $properties['nocache_hash']; + $resource->file_dependency = $properties['file_dependency']; + if (isset($properties['tpl_function'])) { + $tpl->tpl_function = $properties['tpl_function']; + } + } + return $is_valid && !function_exists($properties['unifunc']); + } + + /** * Compiles the template * If the template is not evaluated the compiled template is saved on disk diff --git a/libs/sysplugins/smarty_internal_testinstall.php b/libs/sysplugins/smarty_internal_testinstall.php index 72d9a521..e277f85b 100644 --- a/libs/sysplugins/smarty_internal_testinstall.php +++ b/libs/sysplugins/smarty_internal_testinstall.php @@ -480,7 +480,6 @@ class Smarty_Internal_TestInstall 'smarty_internal_runtime_tplfunction.php' => true, 'smarty_internal_runtime_updatecache.php' => true, 'smarty_internal_runtime_updatescope.php' => true, - 'smarty_internal_runtime_validatecompiled.php' => true, 'smarty_internal_runtime_var.php' => true, 'smarty_internal_runtime_writefile.php' => true, 'smarty_internal_smartytemplatecompiler.php' => true,