From 8c5f20430deb590eeea4e174febfabea12544671 Mon Sep 17 00:00:00 2001 From: Uwe Tews Date: Thu, 6 Aug 2015 00:57:36 +0200 Subject: [PATCH] optimize duplicate code --- .../smarty_internal_extension_append.php | 19 +------- libs/sysplugins/smarty_internal_template.php | 9 ++-- libs/sysplugins/smarty_template_compiled.php | 44 ++++++++++++------- 3 files changed, 33 insertions(+), 39 deletions(-) diff --git a/libs/sysplugins/smarty_internal_extension_append.php b/libs/sysplugins/smarty_internal_extension_append.php index 0845fb2f..460411f6 100644 --- a/libs/sysplugins/smarty_internal_extension_append.php +++ b/libs/sysplugins/smarty_internal_extension_append.php @@ -27,24 +27,7 @@ class Smarty_Internal_Extension_Append // $tpl_var is an array, ignore $value foreach ($tpl_var as $_key => $_val) { if ($_key != '') { - if (!isset($obj->tpl_vars[$_key])) { - $tpl_var_inst = Smarty_Internal_Extension_GetVars::getVariable($obj, $_key, null, true, false); - if ($tpl_var_inst instanceof Smarty_Undefined_Variable) { - $obj->tpl_vars[$_key] = new Smarty_Variable(null, $nocache); - } else { - $obj->tpl_vars[$_key] = clone $tpl_var_inst; - } - } - if (!(is_array($obj->tpl_vars[$_key]->value) || $obj->tpl_vars[$_key]->value instanceof ArrayAccess)) { - settype($obj->tpl_vars[$_key]->value, 'array'); - } - if ($merge && is_array($_val)) { - foreach ($_val as $_mkey => $_mval) { - $obj->tpl_vars[$_key]->value[$_mkey] = $_mval; - } - } else { - $obj->tpl_vars[$_key]->value[] = $_val; - } + self::append($obj, $_key, $_val, $merge, $nocache); } } } else { diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index 8048d1d0..b12f51cc 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -661,11 +661,10 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase if (isset($properties['cache_lifetime'])) { $this->properties['cache_lifetime'] = $properties['cache_lifetime']; } - if (isset($properties['file_dependency'])) { - $this->properties['file_dependency'] = array_merge($this->properties['file_dependency'], $properties['file_dependency']); - } - if (isset($properties['tpl_function'])) { - $this->properties['tpl_function'] = array_merge($this->properties['tpl_function'], $properties['tpl_function']); + foreach (array('file_dependency', 'tpl_function') as $property) { + if (isset($properties[$property])) { + $this->properties[$property] = array_merge($this->properties[$property], $properties[$property]); + } } $this->properties['version'] = $properties['version']; $this->properties['unifunc'] = $properties['unifunc']; diff --git a/libs/sysplugins/smarty_template_compiled.php b/libs/sysplugins/smarty_template_compiled.php index 22f47c1b..f6e95054 100644 --- a/libs/sysplugins/smarty_template_compiled.php +++ b/libs/sysplugins/smarty_template_compiled.php @@ -46,6 +46,13 @@ class Smarty_Template_Compiled */ public $code = null; + /** + * unique function name for compiled template code + * + * @var string + */ + public $unifunc = ''; + /** * create Compiled Object container */ @@ -173,14 +180,7 @@ class Smarty_Template_Compiled ob_get_clean(); $this->code = null; } else { - if (function_exists('opcache_invalidate')) { - opcache_invalidate($_template->compiled->filepath); - } - if (strpos(phpversion(), 'hhvm') !== false) { - Smarty_Internal_Extension_Hhvm::includeHhvm($_template, $_template->compiled->filepath); - } else { - include($_template->compiled->filepath); - } + $this->loadCompiledTemplate($_template); } $_template->smarty->compile_check = $compileCheck; } else { @@ -189,14 +189,7 @@ class Smarty_Template_Compiled $this->compileTemplateSource($_template); $compileCheck = $_template->smarty->compile_check; $_template->smarty->compile_check = false; - if (function_exists('opcache_invalidate')) { - opcache_invalidate($_template->compiled->filepath); - } - if (strpos(phpversion(), 'hhvm') !== false) { - Smarty_Internal_Extension_Hhvm::includeHhvm($_template, $_template->compiled->filepath); - } else { - include($_template->compiled->filepath); - } + $this->loadCompiledTemplate($_template); $_template->smarty->compile_check = $compileCheck; } } @@ -204,6 +197,25 @@ class Smarty_Template_Compiled $this->processed = true; } + /** + * Load fresh compiled template by including the PHP file + * HHVM requires a work around because of a PHP incompatibility + * + * @param \Smarty_Internal_Template $_template + */ + private function loadCompiledTemplate(Smarty_Internal_Template $_template) + { + if (function_exists('opcache_invalidate')) { + opcache_invalidate($_template->compiled->filepath); + } + $_smarty_tpl = $_template; + if (strpos(phpversion(), 'hhvm') !== false) { + Smarty_Internal_Extension_Hhvm::includeHhvm($_template, $_template->compiled->filepath); + } else { + include($_template->compiled->filepath); + } + } + /** * render compiled template code *