mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
optimize duplicate code
This commit is contained in:
@@ -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 {
|
||||
|
@@ -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']);
|
||||
foreach (array('file_dependency', 'tpl_function') as $property) {
|
||||
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['unifunc'] = $properties['unifunc'];
|
||||
|
@@ -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
|
||||
*
|
||||
|
Reference in New Issue
Block a user