optimize duplicate code

This commit is contained in:
Uwe Tews
2015-08-06 00:57:36 +02:00
parent 80ee385965
commit 8c5f20430d
3 changed files with 33 additions and 39 deletions

View File

@@ -27,24 +27,7 @@ class Smarty_Internal_Extension_Append
// $tpl_var is an array, ignore $value // $tpl_var is an array, ignore $value
foreach ($tpl_var as $_key => $_val) { foreach ($tpl_var as $_key => $_val) {
if ($_key != '') { if ($_key != '') {
if (!isset($obj->tpl_vars[$_key])) { self::append($obj, $_key, $_val, $merge, $nocache);
$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;
}
} }
} }
} else { } else {

View File

@@ -661,11 +661,10 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
if (isset($properties['cache_lifetime'])) { if (isset($properties['cache_lifetime'])) {
$this->properties['cache_lifetime'] = $properties['cache_lifetime']; $this->properties['cache_lifetime'] = $properties['cache_lifetime'];
} }
if (isset($properties['file_dependency'])) { foreach (array('file_dependency', 'tpl_function') as $property) {
$this->properties['file_dependency'] = array_merge($this->properties['file_dependency'], $properties['file_dependency']); if (isset($properties[$property])) {
$this->properties[$property] = array_merge($this->properties[$property], $properties[$property]);
} }
if (isset($properties['tpl_function'])) {
$this->properties['tpl_function'] = array_merge($this->properties['tpl_function'], $properties['tpl_function']);
} }
$this->properties['version'] = $properties['version']; $this->properties['version'] = $properties['version'];
$this->properties['unifunc'] = $properties['unifunc']; $this->properties['unifunc'] = $properties['unifunc'];

View File

@@ -46,6 +46,13 @@ class Smarty_Template_Compiled
*/ */
public $code = null; public $code = null;
/**
* unique function name for compiled template code
*
* @var string
*/
public $unifunc = '';
/** /**
* create Compiled Object container * create Compiled Object container
*/ */
@@ -173,14 +180,7 @@ class Smarty_Template_Compiled
ob_get_clean(); ob_get_clean();
$this->code = null; $this->code = null;
} else { } else {
if (function_exists('opcache_invalidate')) { $this->loadCompiledTemplate($_template);
opcache_invalidate($_template->compiled->filepath);
}
if (strpos(phpversion(), 'hhvm') !== false) {
Smarty_Internal_Extension_Hhvm::includeHhvm($_template, $_template->compiled->filepath);
} else {
include($_template->compiled->filepath);
}
} }
$_template->smarty->compile_check = $compileCheck; $_template->smarty->compile_check = $compileCheck;
} else { } else {
@@ -189,14 +189,7 @@ class Smarty_Template_Compiled
$this->compileTemplateSource($_template); $this->compileTemplateSource($_template);
$compileCheck = $_template->smarty->compile_check; $compileCheck = $_template->smarty->compile_check;
$_template->smarty->compile_check = false; $_template->smarty->compile_check = false;
if (function_exists('opcache_invalidate')) { $this->loadCompiledTemplate($_template);
opcache_invalidate($_template->compiled->filepath);
}
if (strpos(phpversion(), 'hhvm') !== false) {
Smarty_Internal_Extension_Hhvm::includeHhvm($_template, $_template->compiled->filepath);
} else {
include($_template->compiled->filepath);
}
$_template->smarty->compile_check = $compileCheck; $_template->smarty->compile_check = $compileCheck;
} }
} }
@@ -204,6 +197,25 @@ class Smarty_Template_Compiled
$this->processed = true; $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 * render compiled template code
* *