- improve template scope handling

This commit is contained in:
uwetews
2015-10-29 22:17:35 +01:00
parent a0f583078d
commit 55f38125a4
17 changed files with 262 additions and 323 deletions

View File

@@ -1,4 +1,7 @@
 ===== 3.1.28-dev===== (xx.xx.2015)  ===== 3.1.28-dev===== (xx.xx.2015)
29.10.2015
- improve template scope handling
24.10.2015 24.10.2015
- more optimizations of template processing - more optimizations of template processing
- bugfix Error when using {include} within {capture} https://github.com/smarty-php/smarty/issues/100 - bugfix Error when using {include} within {capture} https://github.com/smarty-php/smarty/issues/100

View File

@@ -87,21 +87,16 @@ if (!class_exists('Smarty_Autoloader', false)) {
/** /**
* Load always needed external class files * Load always needed external class files
*/ */
if (!class_exists('Smarty_Internal_Data', false)) {
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_data.php';
if (false) {
if (!class_exists('Smarty_Internal_Data', false)) {
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_data.php';
}
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_extension_handler.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_templatebase.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_template.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_resource.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_resource_file.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_variable.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_source.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_resource_base.php';
} }
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_extension_handler.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_templatebase.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_template.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_resource.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_variable.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_source.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_resource_base.php';
/** /**
* This is the main Smarty class * This is the main Smarty class
@@ -123,18 +118,24 @@ class Smarty extends Smarty_Internal_TemplateBase
/** /**
* smarty version * smarty version
*/ */
const SMARTY_VERSION = '3.1.28-dev/73'; const SMARTY_VERSION = '3.1.28-dev/75';
/** /**
* define variable scopes * define variable scopes
*/ */
const SCOPE_LOCAL = 0; const SCOPE_LOCAL = 0;
const SCOPE_PARENT = 1; const SCOPE_PARENT = 2;
const SCOPE_ROOT = 2; const SCOPE_TPL_ROOT = 4;
const SCOPE_GLOBAL = 3; const SCOPE_ROOT = 8;
const SCOPE_SMARTY = 16;
const SCOPE_GLOBAL = 32;
const SCOPE_BUBBLE_UP = 64;
/** /**
* define caching modes * define caching modes
@@ -262,7 +263,7 @@ class Smarty extends Smarty_Internal_TemplateBase
*/ */
/** /**
* auto literal on delimiters with whitspace * auto literal on delimiters with whitespace
* *
* @var boolean * @var boolean
*/ */
@@ -276,7 +277,7 @@ class Smarty extends Smarty_Internal_TemplateBase
public $error_unassigned = false; public $error_unassigned = false;
/** /**
* look up relative filepaths in include_path * look up relative file path in include_path
* *
* @var boolean * @var boolean
*/ */
@@ -1070,7 +1071,9 @@ class Smarty extends Smarty_Internal_TemplateBase
} else { } else {
$data = null; $data = null;
} }
if ($this->caching && isset($this->_cache['isCached'][$_templateId = $this->_getTemplateId($template, $cache_id, $compile_id)])) { if ($this->caching &&
isset($this->_cache['isCached'][$_templateId = $this->_getTemplateId($template, $cache_id, $compile_id)])
) {
$tpl = $do_clone ? clone $this->_cache['isCached'][$_templateId] : $this->_cache['isCached'][$_templateId]; $tpl = $do_clone ? clone $this->_cache['isCached'][$_templateId] : $this->_cache['isCached'][$_templateId];
$tpl->parent = $parent; $tpl->parent = $parent;
$tpl->tpl_vars = array(); $tpl->tpl_vars = array();
@@ -1119,6 +1122,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* @param string $template_name * @param string $template_name
* @param null|mixed $cache_id * @param null|mixed $cache_id
* @param null|mixed $compile_id * @param null|mixed $compile_id
* @param null $caching
* *
* @return string * @return string
*/ */
@@ -1129,7 +1133,8 @@ class Smarty extends Smarty_Internal_TemplateBase
$caching = (int) ($caching === null ? $this->caching : $caching); $caching = (int) ($caching === null ? $this->caching : $caching);
if ($this->allow_ambiguous_resources) { if ($this->allow_ambiguous_resources) {
$_templateId = Smarty_Resource::getUniqueTemplateName($this, $template_name) . "#{$cache_id}#{$compile_id}#{$caching}"; $_templateId =
Smarty_Resource::getUniqueTemplateName($this, $template_name) . "#{$cache_id}#{$compile_id}#{$caching}";
} else { } else {
$_templateId = $this->_joined_template_dir . "#{$template_name}#{$cache_id}#{$compile_id}#{$caching}"; $_templateId = $this->_joined_template_dir . "#{$template_name}#{$cache_id}#{$compile_id}#{$caching}";
} }
@@ -1156,7 +1161,8 @@ class Smarty extends Smarty_Internal_TemplateBase
if ($pattern == null) { if ($pattern == null) {
$nds = DS == '/' ? '\\' : '/'; $nds = DS == '/' ? '\\' : '/';
$ds = '\\' . DS; $ds = '\\' . DS;
$pattern = "#([{$ds}]+[^{$ds}]+[{$ds}]+[.]([{$ds}]+[.])*[.][{$ds}]+([.][{$ds}]+)*)|([{$ds}]+([.][{$ds}]+)+)|[{$ds}]{2,}#"; $pattern =
"#([{$ds}]+[^{$ds}]+[{$ds}]+[.]([{$ds}]+[.])*[.][{$ds}]+([.][{$ds}]+)*)|([{$ds}]+([.][{$ds}]+)+)|[{$ds}]{2,}#";
} }
// normalize DS // normalize DS
if (strpos($path, $nds) !== false) { if (strpos($path, $nds) !== false) {
@@ -1386,8 +1392,8 @@ class Smarty extends Smarty_Internal_TemplateBase
if (!isset(Smarty::$_muted_directories[SMARTY_DIR])) { if (!isset(Smarty::$_muted_directories[SMARTY_DIR])) {
$smarty_dir = realpath(SMARTY_DIR); $smarty_dir = realpath(SMARTY_DIR);
if ($smarty_dir !== false) { if ($smarty_dir !== false) {
Smarty::$_muted_directories[SMARTY_DIR] = array('file' => $smarty_dir, Smarty::$_muted_directories[SMARTY_DIR] =
'length' => strlen($smarty_dir),); array('file' => $smarty_dir, 'length' => strlen($smarty_dir),);
} }
} }
@@ -1413,7 +1419,8 @@ class Smarty extends Smarty_Internal_TemplateBase
// or the error was within smarty but masked to be ignored // or the error was within smarty but masked to be ignored
if (!$_is_muted_directory || ($errno && $errno & error_reporting())) { if (!$_is_muted_directory || ($errno && $errno & error_reporting())) {
if (Smarty::$_previous_error_handler) { if (Smarty::$_previous_error_handler) {
return call_user_func(Smarty::$_previous_error_handler, $errno, $errstr, $errfile, $errline, $errcontext); return call_user_func(Smarty::$_previous_error_handler, $errno, $errstr, $errfile, $errline,
$errcontext);
} else { } else {
return false; return false;
} }

View File

@@ -38,13 +38,6 @@ class Smarty_Data extends Smarty_Internal_Data
*/ */
public $smarty = null; public $smarty = null;
/**
* This object type (Smarty = 1, template = 2, data = 4)
*
* @var int
*/
public $_objType = 4;
/** /**
* create Smarty data object * create Smarty data object
* *

View File

@@ -55,31 +55,30 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
$_scope = Smarty::SCOPE_ROOT; $_scope = Smarty::SCOPE_ROOT;
} elseif ($_attr['scope'] == 'global') { } elseif ($_attr['scope'] == 'global') {
$_scope = Smarty::SCOPE_GLOBAL; $_scope = Smarty::SCOPE_GLOBAL;
} elseif ($_attr['scope'] == 'smarty') {
$_scope = Smarty::SCOPE_SMARTY;
} elseif ($_attr['scope'] == 'tpl_root') {
$_scope = Smarty::SCOPE_TPL_ROOT;
} else { } else {
$compiler->trigger_template_error('illegal value for "scope" attribute', null, true); $compiler->trigger_template_error('illegal value for "scope" attribute', null, true);
} }
$_scope += (isset($_attr['bubble_up']) && $_attr['bubble_up'] == 'false') ? 0 : Smarty::SCOPE_BUBBLE_UP;
} }
// compiled output // compiled output
if (isset($parameter['smarty_internal_index'])) { if (isset($parameter['smarty_internal_index'])) {
$output = "<?php \$_smarty_tpl->smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, $_attr[var], $_nocache, $_scope);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];"; $output = "<?php \$_smarty_tpl->smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, $_attr[var], $_nocache);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];";
} else { } else {
// implement Smarty2's behaviour of variables assigned by reference // implement Smarty2's behaviour of variables assigned by reference
if ($compiler->template->smarty instanceof SmartyBC) { if ($compiler->template->smarty instanceof SmartyBC) {
$output = "<?php if (isset(\$_smarty_tpl->tpl_vars[$_attr[var]])) {\$_smarty_tpl->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];"; $output = "<?php if (isset(\$_smarty_tpl->tpl_vars[$_attr[var]])) {\$_smarty_tpl->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];";
$output .= "\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value = $_attr[value]; \$_smarty_tpl->tpl_vars[$_attr[var]]->nocache = $_nocache; \$_smarty_tpl->tpl_vars[$_attr[var]]->scope = $_scope;"; $output .= "\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value = $_attr[value]; \$_smarty_tpl->tpl_vars[$_attr[var]]->nocache = $_nocache;";
$output .= "\n} else \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_Variable($_attr[value], $_nocache, $_scope);"; $output .= "\n} else \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_Variable($_attr[value], $_nocache);";
} else { } else {
$output = "<?php \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_Variable($_attr[value], $_nocache, $_scope);"; $output = "<?php \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_Variable($_attr[value], $_nocache);";
} }
} }
if ($_scope == Smarty::SCOPE_PARENT) { $output .= "\n\$_smarty_tpl->ext->_updateScope->updateScope(\$_smarty_tpl, $_attr[var], $_scope);";
$output .= "\nif (\$_smarty_tpl->parent != null) \$_smarty_tpl->parent->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];";
} elseif ($_scope == Smarty::SCOPE_ROOT || $_scope == Smarty::SCOPE_GLOBAL) {
$output .= "\n\$_ptr = \$_smarty_tpl->parent; while (\$_ptr != null) {\$_ptr->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]]; \$_ptr = \$_ptr->parent; }";
}
if ($_scope == Smarty::SCOPE_GLOBAL) {
$output .= "\nSmarty::\$global_tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];";
}
$output .= '?>'; $output .= '?>';
return $output; return $output;

View File

@@ -43,7 +43,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* @var array * @var array
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $option_flags = array('nocache', 'inline', 'caching'); public $option_flags = array('nocache', 'inline', 'caching', 'bubble_up');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
@@ -113,10 +113,17 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$_parent_scope = Smarty::SCOPE_ROOT; $_parent_scope = Smarty::SCOPE_ROOT;
} elseif ($_attr['scope'] == 'global') { } elseif ($_attr['scope'] == 'global') {
$_parent_scope = Smarty::SCOPE_GLOBAL; $_parent_scope = Smarty::SCOPE_GLOBAL;
} elseif ($_attr['scope'] == 'smarty') {
$_parent_scope = Smarty::SCOPE_SMARTY;
} elseif ($_attr['scope'] == 'tpl_root') {
$_parent_scope = Smarty::SCOPE_TPL_ROOT;
} }
} }
if ($_attr['bubble_up'] === true) {
$_parent_scope = $_parent_scope + Smarty::SCOPE_BUBBLE_UP;
}
// // set flag to cache subtemplate object when called within loop or template name is variable.
if ($cache_tpl || $variable_template || $compiler->loopNesting > 0) { if ($cache_tpl || $variable_template || $compiler->loopNesting > 0) {
$_cache_tpl = 'true'; $_cache_tpl = 'true';
} else { } else {
@@ -215,7 +222,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
} }
} }
// delete {include} standard attributes // delete {include} standard attributes
unset($_attr['file'], $_attr['assign'], $_attr['cache_id'], $_attr['compile_id'], $_attr['cache_lifetime'], $_attr['nocache'], $_attr['caching'], $_attr['scope'], $_attr['inline']); unset($_attr['file'], $_attr['assign'], $_attr['cache_id'], $_attr['compile_id'], $_attr['cache_lifetime'], $_attr['nocache'], $_attr['caching'], $_attr['scope'], $_attr['inline'], $_attr['bubble_up']);
// remaining attributes must be assigned as smarty variable // remaining attributes must be assigned as smarty variable
$_vars_nc = ''; $_vars_nc = '';
if (!empty($_attr)) { if (!empty($_attr)) {
@@ -248,9 +255,9 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
if (isset($_assign)) { if (isset($_assign)) {
$_output .= "ob_start();\n"; $_output .= "ob_start();\n";
} }
$_output .= "\$_smarty_tpl->smarty->ext->_inline->render(\$_smarty_tpl, {$fullResourceName}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_parent_scope}, {$_cache_tpl}, '{$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['uid']}', '{$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['func']}');\n"; $_output .= "\$_smarty_tpl->smarty->ext->_subtemplate->render(\$_smarty_tpl, {$fullResourceName}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_parent_scope}, {$_cache_tpl}, '{$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['uid']}', '{$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['func']}');\n";
if (isset($_assign)) { if (isset($_assign)) {
$_output .= "\$_smarty_tpl->tpl_vars[$_assign] = new Smarty_Variable(ob_get_clean());\n"; $_output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n";
} }
if ($update_compile_id) { if ($update_compile_id) {
$_output .= $compiler->makeNocacheCode("\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n"); $_output .= $compiler->makeNocacheCode("\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n");
@@ -273,7 +280,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
} }
$_output .= "\$_smarty_tpl->smarty->ext->_subtemplate->render(\$_smarty_tpl, {$fullResourceName}, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_parent_scope, {$_cache_tpl});\n"; $_output .= "\$_smarty_tpl->smarty->ext->_subtemplate->render(\$_smarty_tpl, {$fullResourceName}, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_parent_scope, {$_cache_tpl});\n";
if (isset($_assign)) { if (isset($_assign)) {
$_output .= "\$_smarty_tpl->tpl_vars[$_assign] = new Smarty_Variable(ob_get_clean());\n"; $_output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n";
} }
if ($update_compile_id) { if ($update_compile_id) {
$_output .= "\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n"; $_output .= "\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n";

View File

@@ -20,10 +20,17 @@
* @method Smarty_Internal_Data clearAllAssign() * @method Smarty_Internal_Data clearAllAssign()
* @method Smarty_Internal_Data clearConfig(string $varName = null) * @method Smarty_Internal_Data clearConfig(string $varName = null)
* @method Smarty_Internal_Data configLoad(string $config_file, mixed $sections = null, string $scope = 'local') * @method Smarty_Internal_Data configLoad(string $config_file, mixed $sections = null, string $scope = 'local')
* @property int $_objType * @property int $scope
*/ */
class Smarty_Internal_Data class Smarty_Internal_Data
{ {
/**
* This object type (Smarty = 1, template = 2, data = 4)
*
* @var int
*/
public $_objType = 4;
/** /**
* name of class used for templates * name of class used for templates
* *
@@ -34,7 +41,7 @@ class Smarty_Internal_Data
/** /**
* template variables * template variables
* *
* @var array * @var Smarty_Variable[]
*/ */
public $tpl_vars = array(); public $tpl_vars = array();
@@ -48,7 +55,7 @@ class Smarty_Internal_Data
/** /**
* configuration settings * configuration settings
* *
* @var array * @var string[]
*/ */
public $config_vars = array(); public $config_vars = array();
@@ -67,6 +74,7 @@ class Smarty_Internal_Data
public function __construct() public function __construct()
{ {
$this->ext = new Smarty_Internal_Extension_Handler(); $this->ext = new Smarty_Internal_Extension_Handler();
$this->ext->objType = $this->_objType;
} }
/** /**
@@ -85,14 +93,19 @@ class Smarty_Internal_Data
foreach ($tpl_var as $_key => $_val) { foreach ($tpl_var as $_key => $_val) {
if ($_key != '') { if ($_key != '') {
$this->tpl_vars[$_key] = new Smarty_Variable($_val, $nocache); $this->tpl_vars[$_key] = new Smarty_Variable($_val, $nocache);
if ($this->_objType == 2 && $this->scope) {
$this->ext->_updateScope->updateScope($this, $_key);
}
} }
} }
} else { } else {
if ($tpl_var != '') { if ($tpl_var != '') {
$this->tpl_vars[$tpl_var] = new Smarty_Variable($value, $nocache); $this->tpl_vars[$tpl_var] = new Smarty_Variable($value, $nocache);
if ($this->_objType == 2 && $this->scope) {
$this->ext->_updateScope->updateScope($this, $tpl_var);
}
} }
} }
return $this; return $this;
} }
@@ -127,7 +140,7 @@ class Smarty_Internal_Data
public function assignGlobal($varName, $value = null, $nocache = false) public function assignGlobal($varName, $value = null, $nocache = false)
{ {
return $this->ext->assignGlobal->assignGlobal($this, $varName, $value, $nocache); return $this->ext->assignGlobal->assignGlobal($this, $varName, $value, $nocache);
} }
/** /**
* appends values to template variables by reference * appends values to template variables by reference
@@ -163,15 +176,15 @@ class Smarty_Internal_Data
* @api Smarty::getTemplateVars() * @api Smarty::getTemplateVars()
* @link http://www.smarty.net/docs/en/api.get.template.vars.tpl * @link http://www.smarty.net/docs/en/api.get.template.vars.tpl
* *
* @param string $varName variable name or null * @param string $varName variable name or null
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object
* @param bool $searchParents include parent templates? * @param bool $searchParents include parent templates?
* *
* @return mixed variable value or or array of variables * @return mixed variable value or or array of variables
*/ */
public function getTemplateVars($varName = null, Smarty_Internal_Data $_ptr = null, $searchParents = true) public function getTemplateVars($varName = null, Smarty_Internal_Data $_ptr = null, $searchParents = true)
{ {
return $this->ext->getTemplateVars->getTemplateVars($this, $varName, $_ptr, $searchParents); return $this->ext->getTemplateVars->getTemplateVars($this, $varName, $_ptr, $searchParents);
} }
/** /**
@@ -179,7 +192,8 @@ class Smarty_Internal_Data
* *
* @param \Smarty_Internal_Data|null $data * @param \Smarty_Internal_Data|null $data
*/ */
public function _mergeVars(Smarty_Internal_Data $data = null) { public function _mergeVars(Smarty_Internal_Data $data = null)
{
if (isset($data)) { if (isset($data)) {
if (!empty($this->tpl_vars)) { if (!empty($this->tpl_vars)) {
$data->tpl_vars = array_merge($this->tpl_vars, $data->tpl_vars); $data->tpl_vars = array_merge($this->tpl_vars, $data->tpl_vars);
@@ -190,7 +204,7 @@ class Smarty_Internal_Data
} else { } else {
$data = $this; $data = $this;
} }
if (isset($this->parent)) { if (isset($this->parent)) {
$this->parent->_mergeVars($data); $this->parent->_mergeVars($data);
} }
} }

View File

@@ -10,36 +10,37 @@
* @subpackage PluginsInternal * @subpackage PluginsInternal
* @author Uwe Tews * @author Uwe Tews
* *
* @property Smarty_Internal_Runtime_Inheritance $_inheritance * @property Smarty_Internal_Runtime_Inheritance $_inheritance
* @property Smarty_Internal_Runtime_SubTemplate $_subTemplate * @property Smarty_Internal_Runtime_SubTemplate $_subTemplate
* @property Smarty_Internal_Runtime_Inline $_inline * @property Smarty_Internal_Runtime_TplFunction $_tplFunction
* @property Smarty_Internal_Runtime_TplFunction $_tplFunction * @property Smarty_Internal_Runtime_Var $_var
* @property Smarty_Internal_Runtime_Var $_var * @property Smarty_Internal_Runtime_Config $_config
* @property Smarty_Internal_Runtime_Config $_config * @property Smarty_Internal_Runtime_Foreach $_foreach
* @property Smarty_Internal_Runtime_Foreach $_foreach * @property Smarty_Internal_Runtime_Hhvm $_hhvm
* @property Smarty_Internal_Runtime_Hhvm $_hhvm * @property Smarty_Internal_Runtime_WriteFile $_writeFile
* @property Smarty_Internal_Runtime_WriteFile $_writeFile
* @property Smarty_Internal_Runtime_ValidateCompiled $_validateCompiled * @property Smarty_Internal_Runtime_ValidateCompiled $_validateCompiled
* @property Smarty_Internal_Runtime_CodeFrame $_codeFrame * @property Smarty_Internal_Runtime_CodeFrame $_codeFrame
* @property Smarty_Internal_Runtime_FilterHandler $_filterHandler * @property Smarty_Internal_Runtime_FilterHandler $_filterHandler
* @property Smarty_Internal_Runtime_GetIncludePath $_getIncludePath * @property Smarty_Internal_Runtime_GetIncludePath $_getIncludePath
* @property Smarty_Internal_Runtime_Source $_source * @property Smarty_Internal_Runtime_UpdateScope $_updateScope
* @property Smarty_Internal_Runtime_IsCached $_isCached * @property Smarty_Internal_Runtime_IsCached $_isCached
* @property Smarty_Internal_Runtime_CacheModify $_cacheModify * @property Smarty_Internal_Runtime_CacheModify $_cacheModify
* @property Smarty_Internal_Runtime_UpdateCache $_updateCache * @property Smarty_Internal_Runtime_UpdateCache $_updateCache
* @property Smarty_Internal_Method_GetTemplateVars $getTemplateVars * @property Smarty_Internal_Method_GetTemplateVars $getTemplateVars
* @property Smarty_Internal_Method_Append $append * @property Smarty_Internal_Method_Append $append
* @property Smarty_Internal_Method_AppendByRef $appendByRef * @property Smarty_Internal_Method_AppendByRef $appendByRef
* @property Smarty_Internal_Method_AssignGlobal $assignGlobal * @property Smarty_Internal_Method_AssignGlobal $assignGlobal
* @property Smarty_Internal_Method_AssignByRef $assignByRef * @property Smarty_Internal_Method_AssignByRef $assignByRef
* @property Smarty_Internal_Method_LoadFilter $loadFilter * @property Smarty_Internal_Method_LoadFilter $loadFilter
* @property Smarty_Internal_Method_RegisterFilter $registerFilter * @property Smarty_Internal_Method_RegisterFilter $registerFilter
* @property Smarty_Internal_Method_RegisterObject $registerObject * @property Smarty_Internal_Method_RegisterObject $registerObject
* @property Smarty_Internal_Method_RegisterPlugin $registerPlugin * @property Smarty_Internal_Method_RegisterPlugin $registerPlugin
*/ */
class Smarty_Internal_Extension_Handler class Smarty_Internal_Extension_Handler
{ {
public $objType = null;
/** /**
* Cache for property information from generic getter/setter * Cache for property information from generic getter/setter
* Preloaded with names which should not use with generic getter/setter * Preloaded with names which should not use with generic getter/setter
@@ -52,46 +53,47 @@ class Smarty_Internal_Extension_Handler
private $resolvedProperties = array(); private $resolvedProperties = array();
/** /**
* Call external Method * Call external Method
* *
* @param \Smarty_Internal_Data $data * @param \Smarty_Internal_Data $data
* @param string $name external method names * @param string $name external method names
* @param array $args argument array * @param array $args argument array
* *
* @return mixed * @return mixed
* @throws SmartyException * @throws SmartyException
*/ */
public function _callExternalMethod(Smarty_Internal_Data $data, $name, $args) { public function _callExternalMethod(Smarty_Internal_Data $data, $name, $args)
/* @var Smarty $data->smarty */ {
/* @var Smarty $data ->smarty */
$smarty = isset($data->smarty) ? $data->smarty : $data; $smarty = isset($data->smarty) ? $data->smarty : $data;
if (!isset($smarty->ext->$name)) { if (!isset($smarty->ext->$name)) {
$class = 'Smarty_Internal_Method_' . ucfirst($name); $class = 'Smarty_Internal_Method_' . ucfirst($name);
if (preg_match('/^(set|get)([A-Z].*)$/', $name, $match)) { if (preg_match('/^(set|get)([A-Z].*)$/', $name, $match)) {
if (!isset($this->_property_info[$prop = $match[2]])) { if (!isset($this->_property_info[$prop = $match[2]])) {
// convert camel case to underscored name // convert camel case to underscored name
$this->resolvedProperties[$prop] = $pn = strtolower(join('_', preg_split('/([A-Z][^A-Z]*)/', $prop, - 1, PREG_SPLIT_NO_EMPTY | $this->resolvedProperties[$prop] = $pn = strtolower(join('_',
PREG_SPLIT_DELIM_CAPTURE))); preg_split('/([A-Z][^A-Z]*)/', $prop, - 1,
$this->_property_info[$prop] = property_exists($data, $pn) ? 1 : ($data->_objType == 2 && PREG_SPLIT_NO_EMPTY |
property_exists($smarty, $pn) ? 2 : 0); PREG_SPLIT_DELIM_CAPTURE)));
} $this->_property_info[$prop] = property_exists($data, $pn) ? 1 :
if ($this->_property_info[$prop]) { ($data->_objType == 2 && property_exists($smarty, $pn) ? 2 : 0);
$pn = $this->resolvedProperties[$prop]; }
if ($match[1] == 'get') { if ($this->_property_info[$prop]) {
return $this->_property_info[$prop] == 1 ? $data->$pn : $data->smarty->$pn; $pn = $this->resolvedProperties[$prop];
} else { if ($match[1] == 'get') {
return $this->_property_info[$prop] == return $this->_property_info[$prop] == 1 ? $data->$pn : $data->smarty->$pn;
1 ? $data->$pn = $args[0] : $data->smarty->$pn = $args[0]; } else {
return $this->_property_info[$prop] == 1 ? $data->$pn = $args[0] :
$data->smarty->$pn = $args[0];
}
} elseif (!class_exists($class)) {
throw new SmartyException("property '$pn' does not exist.");
} }
} elseif (!class_exists($class)) {
throw new SmartyException("property '$pn' does not exist.");
} }
} if (class_exists($class)) {
if (class_exists($class)) { $callback = array($smarty->ext->$name = new $class(), $name);
$callback = array($smarty->ext->$name = new $class(), $name); }
}
} else { } else {
$callback = array($smarty->ext->$name, $name); $callback = array($smarty->ext->$name, $name);
} }
@@ -100,7 +102,7 @@ class Smarty_Internal_Extension_Handler
return call_user_func_array($callback, $args); return call_user_func_array($callback, $args);
} }
return call_user_func_array(array(new Smarty_Internal_Undefined(), $name), $args); return call_user_func_array(array(new Smarty_Internal_Undefined(), $name), $args);
} }
/** /**
* set extension property * set extension property
@@ -112,7 +114,7 @@ class Smarty_Internal_Extension_Handler
*/ */
public function __set($property_name, $value) public function __set($property_name, $value)
{ {
$this->$property_name = $value; $this->$property_name = $value;
} }
/** /**
@@ -130,7 +132,6 @@ class Smarty_Internal_Extension_Handler
$class = 'Smarty_Internal_Runtime_' . ucfirst(substr($property_name, 1)); $class = 'Smarty_Internal_Runtime_' . ucfirst(substr($property_name, 1));
} else { } else {
$class = 'Smarty_Internal_Method_' . ucfirst($property_name); $class = 'Smarty_Internal_Method_' . ucfirst($property_name);
} }
if (class_exists($class)) { if (class_exists($class)) {
return $this->$property_name = new $class(); return $this->$property_name = new $class();

View File

@@ -39,7 +39,7 @@ class Smarty_Internal_Method_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 != '') {
self::append($data, $_key, $_val, $merge, $nocache); $this->append($data, $_key, $_val, $merge, $nocache);
} }
} }
} else { } else {
@@ -65,6 +65,9 @@ class Smarty_Internal_Method_Append
$data->tpl_vars[$tpl_var]->value[] = $value; $data->tpl_vars[$tpl_var]->value[] = $value;
} }
} }
if ($data->_objType == 2 && $data->scope) {
$data->ext->_updateScope->updateScope($data, $tpl_var);
}
} }
return $data; return $data;
} }

View File

@@ -41,6 +41,9 @@ class Smarty_Internal_Method_AppendByRef
} else { } else {
$data->tpl_vars[$tpl_var]->value[] = &$value; $data->tpl_vars[$tpl_var]->value[] = &$value;
} }
if ($data->_objType == 2 && $data->scope) {
$data->ext->_updateScope->updateScope($data, $tpl_var);
}
} }
return $data; return $data;
} }

View File

@@ -16,9 +16,9 @@ class Smarty_Internal_Method_AssignByRef
* assigns values to template variables by reference * assigns values to template variables by reference
* *
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
* @param string $tpl_var the template variable name * @param string $tpl_var the template variable name
* @param $value * @param $value
* @param boolean $nocache if true any output of this variable will be not cached * @param boolean $nocache if true any output of this variable will be not cached
* *
* @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
*/ */
@@ -27,8 +27,10 @@ class Smarty_Internal_Method_AssignByRef
if ($tpl_var != '') { if ($tpl_var != '') {
$data->tpl_vars[$tpl_var] = new Smarty_Variable(null, $nocache); $data->tpl_vars[$tpl_var] = new Smarty_Variable(null, $nocache);
$data->tpl_vars[$tpl_var]->value = &$value; $data->tpl_vars[$tpl_var]->value = &$value;
if ($data->_objType == 2 && $data->scope) {
$data->ext->_updateScope->updateScope($data, $tpl_var);
}
} }
return $data; return $data;
} }
} }

View File

@@ -1,85 +0,0 @@
<?php
/**
* Inline Runtime Methods render, setSourceByUid, setupSubTemplate
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*
**/
class Smarty_Internal_Runtime_Inline
{
/**
* Template code runtime function to set up an inline subtemplate
*
* @param \Smarty_Internal_Template $parent
* @param string $template template name
* @param mixed $cache_id cache id
* @param mixed $compile_id compile id
* @param integer $caching cache mode
* @param integer $cache_lifetime life time of cache data
* @param array $data passed parameter template variables
* @param int $scope scope in which {include} should execute
* @param bool $forceTplCache cache template object
* @param string $uid file dependency uid
* @param string $content_func function name
*
* @throws \Exception
*/
public function render(\Smarty_Internal_Template $parent, $template, $cache_id, $compile_id, $caching,
$cache_lifetime, $data, $scope, $forceTplCache, $uid, $content_func)
{
$tpl = $parent->smarty->ext->_subTemplate->setupSubTemplate($parent, $template, $cache_id, $compile_id, $caching, $cache_lifetime, $data,
$scope, $forceTplCache, $uid);
if ($parent->smarty->debugging) {
$parent->smarty->_debug->start_template($tpl);
$parent->smarty->_debug->start_render($tpl);
}
$tpl->compiled->getRenderedTemplateCode($tpl, $content_func);
if ($parent->smarty->debugging) {
$parent->smarty->_debug->end_template($tpl);
$parent->smarty->_debug->end_render($tpl);
}
if ($tpl->caching == 9999 && $tpl->compiled->has_nocache_code) {
$parent->cached->hashes[$tpl->compiled->nocache_hash] = true;
}
}
/**
* Set source object of inline template by $uid
*
* @param \Smarty_Internal_Template $tpl
* @param string $uid
*
* @throws \SmartyException
*/
public function setSource(Smarty_Internal_Template $tpl, $uid = null)
{
// $uid is set if template is inline
if (isset($uid)) {
// inline templates have same compiled resource
$tpl->compiled = $tpl->parent->compiled;
if (isset($tpl->compiled->file_dependency[$uid])) {
list($filepath, $timestamp, $resource) = $tpl->compiled->file_dependency[$uid];
$tpl->source = new Smarty_Template_Source(isset($tpl->smarty->_cache['resource_handlers'][$resource]) ?
$tpl->smarty->_cache['resource_handlers'][$resource] :
Smarty_Resource::load($tpl->smarty, $resource),
$tpl->smarty, $filepath, $resource, $filepath);
$tpl->source->filepath = $filepath;
$tpl->source->timestamp = $timestamp;
$tpl->source->exists = true;
$tpl->source->uid = $uid;
} else {
$tpl->source = null;
}
} else {
$tpl->source = null;
unset($tpl->compiled);
}
if (!isset($tpl->source)) {
$tpl->source = Smarty_Template_Source::load($tpl);
}
}
}

View File

@@ -11,8 +11,20 @@
class Smarty_Internal_Runtime_SubTemplate class Smarty_Internal_Runtime_SubTemplate
{ {
/**
* Subtemplate template object cache
*
* @var Smarty_Internal_Template[]
*/
public $tplObjects = array(); public $tplObjects = array();
/**
* Subtemplate call count
*
* @var int[]
*/
public $subTplInfo = array(); public $subTplInfo = array();
/** /**
* Runtime function to render subtemplate * Runtime function to render subtemplate
* *
@@ -25,39 +37,20 @@ class Smarty_Internal_Runtime_SubTemplate
* @param array $data passed parameter template variables * @param array $data passed parameter template variables
* @param int $scope scope in which {include} should execute * @param int $scope scope in which {include} should execute
* @param bool $forceTplCache cache template object * @param bool $forceTplCache cache template object
* @param string $uid file dependency uid
* @param string $content_func function name
* *
*/ */
public function render(Smarty_Internal_Template $parent, $template, $cache_id, $compile_id, $caching, public function render(Smarty_Internal_Template $parent, $template, $cache_id, $compile_id, $caching,
$cache_lifetime, $data, $scope, $forceTplCache) $cache_lifetime, $data, $scope, $forceTplCache, $uid = null, $content_func = null)
{$this->setupSubTemplate($parent, $template, $cache_id, $compile_id, $caching, $cache_lifetime, $data,
$scope, $forceTplCache)->render();
}
/**
* Runtime function to get subtemplate object from cache or clone from parent
*
* @param \Smarty_Internal_Template $parent calling template
* @param string $template template name
* @param mixed $cache_id cache id
* @param mixed $compile_id compile id
* @param integer $caching cache mode
* @param integer $cache_lifetime life time of cache data
* @param array $data passed parameter template variables
* @param int $scope scope in which {include} should execute
* @param $forceTplCache
* @param string|null $uid source uid
*
* @return \Smarty_Internal_Template template object
*/
public function setupSubTemplate(Smarty_Internal_Template $parent, $template, $cache_id, $compile_id, $caching,
$cache_lifetime, $data, $scope, $forceTplCache, $uid = null)
{ {
// if there are cached template objects calculate $templateID // if there are cached template objects calculate $templateID
$_templateId = !empty($this->tplObjects) ? $_templateId =
$parent->smarty->_getTemplateId($template, $cache_id, $compile_id, $caching) : null; !empty($this->tplObjects) ? $parent->smarty->_getTemplateId($template, $cache_id, $compile_id, $caching) :
null;
// already in template cache? // already in template cache?
/* @var Smarty_Internal_Template $tpl */ /* @var Smarty_Internal_Template $tpl */
if (isset($this->tplObjects[$_templateId])) { if (isset($_templateId) && isset($this->tplObjects[$_templateId])) {
// clone cached template object because of possible recursive call // clone cached template object because of possible recursive call
$tpl = clone $this->tplObjects[$_templateId]; $tpl = clone $this->tplObjects[$_templateId];
$tpl->parent = $parent; $tpl->parent = $parent;
@@ -66,10 +59,9 @@ class Smarty_Internal_Runtime_SubTemplate
unset($tpl->compiled); unset($tpl->compiled);
} }
// get variables from calling scope // get variables from calling scope
if ($scope == Smarty::SCOPE_LOCAL && $tpl->scope == Smarty::SCOPE_LOCAL) {
$tpl->tpl_vars = $parent->tpl_vars; $tpl->tpl_vars = $parent->tpl_vars;
$tpl->config_vars = $parent->config_vars; $tpl->config_vars = $parent->config_vars;
} // get template functions
$tpl->tpl_function = $parent->tpl_function; $tpl->tpl_function = $parent->tpl_function;
// copy inheritance object? // copy inheritance object?
if (isset($parent->ext->_inheritance)) { if (isset($parent->ext->_inheritance)) {
@@ -86,9 +78,27 @@ class Smarty_Internal_Runtime_SubTemplate
$tpl->cache_id = $cache_id; $tpl->cache_id = $cache_id;
$tpl->compile_id = $compile_id; $tpl->compile_id = $compile_id;
if (isset($uid)) { if (isset($uid)) {
$tpl->ext->_inline->setSource($tpl, $uid); // for inline templates we can get all resource information from file dependency
if (isset($tpl->compiled->file_dependency[$uid])) {
list($filepath, $timestamp, $resource) = $tpl->compiled->file_dependency[$uid];
$tpl->source =
new Smarty_Template_Source(isset($tpl->smarty->_cache['resource_handlers'][$resource]) ?
$tpl->smarty->_cache['resource_handlers'][$resource] :
Smarty_Resource::load($tpl->smarty, $resource), $tpl->smarty,
$filepath, $resource, $filepath);
$tpl->source->filepath = $filepath;
$tpl->source->timestamp = $timestamp;
$tpl->source->exists = true;
$tpl->source->uid = $uid;
} else {
$tpl->source = null;
}
} else { } else {
$this->setSource($tpl, $uid); $tpl->source = null;
}
if (!isset($tpl->source)) {
$tpl->source = Smarty_Template_Source::load($tpl);
unset($tpl->compiled);
} }
unset($tpl->cached); unset($tpl->cached);
} }
@@ -98,37 +108,31 @@ class Smarty_Internal_Runtime_SubTemplate
if ($caching == 9999) { if ($caching == 9999) {
$tpl->cached = $parent->cached; $tpl->cached = $parent->cached;
} }
// get variables from calling scope // set template scope
if ($scope != $tpl->scope) { $tpl->scope = $scope;
if ($tpl->scope != Smarty::SCOPE_LOCAL) { $scopePtr = false;
//We must get rid of pointers if ($scope & ~Smarty::SCOPE_BUBBLE_UP) {
unset($tpl->tpl_vars, $tpl->config_vars); if ($scope == Smarty::SCOPE_GLOBAL) {
$tpl->tpl_vars = array(); $tpl->tpl_vars = Smarty::$global_tpl_vars;
$tpl->config_vars = array(); $scopePtr = true;
} } elseif ($scope == Smarty::SCOPE_PARENT) {
if ($scope == Smarty::SCOPE_PARENT) { $scopePtr = $parent;
$tpl->tpl_vars = &$parent->tpl_vars; } elseif ($scope == Smarty::SCOPE_SMARTY) {
$tpl->config_vars = &$parent->config_vars; $scopePtr = $tpl->smarty;
} elseif ($scope == Smarty::SCOPE_GLOBAL) {
$tpl->tpl_vars = &Smarty::$global_tpl_vars;
$tpl->config_vars = $parent->config_vars;
} elseif ($scope == Smarty::SCOPE_ROOT) {
$ptr = $tpl->parent;
while (!empty($ptr->parent)) {
$ptr = $ptr->parent;
}
$tpl->tpl_vars = &$ptr->tpl_vars;
$tpl->config_vars = &$ptr->config_vars;
} else { } else {
$tpl->tpl_vars = $parent->tpl_vars; $scopePtr = $tpl;
$tpl->config_vars = $parent->config_vars; while (isset($scopePtr->parent)) {
if ($scopePtr->parent->_objType != 2 && $scope & Smarty::SCOPE_TPL_ROOT) {
break;
}
$scopePtr = $scopePtr->parent;
}
} }
$tpl->scope = $scope; $tpl->tpl_vars = $scopePtr->tpl_vars;
$tpl->config_vars = $scopePtr->config_vars;
} }
if (!isset($this->tplObjects[$tpl->_getTemplateId()]) && if (!isset($this->tplObjects[$tpl->_getTemplateId()]) && !$tpl->source->handler->recompiled) {
!$tpl->source->handler->recompiled
) {
// if template is called multiple times set flag to to cache template objects // if template is called multiple times set flag to to cache template objects
$forceTplCache = $forceTplCache || $forceTplCache = $forceTplCache ||
(isset($this->subTplInfo[$tpl->template_resource]) && $this->subTplInfo[$tpl->template_resource] > 1); (isset($this->subTplInfo[$tpl->template_resource]) && $this->subTplInfo[$tpl->template_resource] > 1);
@@ -147,40 +151,49 @@ class Smarty_Internal_Runtime_SubTemplate
$tpl->tpl_vars[$_key] = new Smarty_Variable($_val); $tpl->tpl_vars[$_key] = new Smarty_Variable($_val);
} }
} }
return $tpl; if (isset($uid)) {
} if ($parent->smarty->debugging) {
$parent->smarty->_debug->start_template($tpl);
/** $parent->smarty->_debug->start_render($tpl);
* Set source object of inline template by $uid }
* $tpl->compiled->getRenderedTemplateCode($tpl, $content_func);
* @param \Smarty_Internal_Template $tpl if ($parent->smarty->debugging) {
* @param string $uid $parent->smarty->_debug->end_template($tpl);
* $parent->smarty->_debug->end_render($tpl);
* @throws \SmartyException }
*/ if ($tpl->caching == 9999 && $tpl->compiled->has_nocache_code) {
public function setSource(Smarty_Internal_Template $tpl, $uid = null) $parent->cached->hashes[$tpl->compiled->nocache_hash] = true;
{ }
//load source } else {
$tpl->source = null; if (isset($tpl->compiled)) {
unset($tpl->compiled); $tpl->compiled->render($tpl);
if (!isset($tpl->source)) { } else {
$tpl->source = Smarty_Template_Source::load($tpl); $tpl->render();
}
}
if ($scopePtr) {
if ($scope == Smarty::SCOPE_GLOBAL) {
Smarty::$global_tpl_vars = $tpl->tpl_vars;
} else {
$scopePtr->tpl_vars = $tpl->tpl_vars;
$scopePtr->config_vars = $tpl->config_vars;
}
} }
} }
/** /**
* Get called subtemplates and its call count from compiled template * Get called subtemplates from compiled template and save call count
* *
* @param \Smarty_Internal_Template $tpl * @param \Smarty_Internal_Template $tpl
*/ */
public function registerSubTemplates(Smarty_Internal_Template $tpl) { public function registerSubTemplates(Smarty_Internal_Template $tpl) {
foreach ($tpl->compiled->includes as $name => $count) { foreach ($tpl->compiled->includes as $name => $count) {
if (isset($this->subTplInfo[$name])) { if (isset($this->subTplInfo[$name])) {
$this->subTplInfo[$name] += $count; $this->subTplInfo[$name] += $count;
} else { } else {
$this->subTplInfo[$name] = $count; $this->subTplInfo[$name] = $count;
}
} }
}
} }
} }

View File

@@ -16,18 +16,13 @@ class Smarty_Internal_Runtime_Var
* @param \Smarty_Internal_Template $tpl template object * @param \Smarty_Internal_Template $tpl template object
* @param string $varName template variable name * @param string $varName template variable name
* @param bool $nocache cache mode of variable * @param bool $nocache cache mode of variable
* @param int $scope scope of variable
*/ */
public function createLocalArrayVariable(\Smarty_Internal_Template $tpl, $varName, $nocache = false, public function createLocalArrayVariable(\Smarty_Internal_Template $tpl, $varName, $nocache = false)
$scope = Smarty::SCOPE_LOCAL)
{ {
if (!isset($tpl->tpl_vars[$varName])) { if (!isset($tpl->tpl_vars[$varName])) {
$tpl->tpl_vars[$varName] = new Smarty_Variable(array(), $nocache, $scope); $tpl->tpl_vars[$varName] = new Smarty_Variable(array(), $nocache);
} else { } else {
$tpl->tpl_vars[$varName] = clone $tpl->tpl_vars[$varName]; $tpl->tpl_vars[$varName] = clone $tpl->tpl_vars[$varName];
if ($scope != Smarty::SCOPE_LOCAL) {
$tpl->tpl_vars[$varName]->scope = $scope;
}
if (!(is_array($tpl->tpl_vars[$varName]->value) || if (!(is_array($tpl->tpl_vars[$varName]->value) ||
$tpl->tpl_vars[$varName]->value instanceof ArrayAccess) $tpl->tpl_vars[$varName]->value instanceof ArrayAccess)
) { ) {

View File

@@ -166,7 +166,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
// display or fetch // display or fetch
if ($display) { if ($display) {
if ($this->caching && $this->smarty->cache_modified_check) { if ($this->caching && $this->smarty->cache_modified_check) {
$this->smarty->ext->_cachemodify->cacheModifiedCheck($this->cached, $this, isset($content) ? $content : ob_get_clean()); $this->smarty->ext->_cachemodify->cacheModifiedCheck($this->cached, $this,
isset($content) ? $content : ob_get_clean());
} else { } else {
if ((!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled) && if ((!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled) &&
!$no_output_filter && (isset($this->smarty->autoload_filters['output']) || !$no_output_filter && (isset($this->smarty->autoload_filters['output']) ||
@@ -324,8 +325,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
case 'compiled': case 'compiled':
case 'cached': case 'cached':
case 'compiler': case 'compiler':
case 'tpl_vars':
case 'config_vars':
$this->$property_name = $value; $this->$property_name = $value;
return; return;
default: default:

View File

@@ -14,12 +14,12 @@
* @package Smarty * @package Smarty
* @subpackage Template * @subpackage Template
* *
* @property Smarty $smarty
* @method Smarty_Internal_TemplateBase setAutoloadFilters(mixed $filters, string $type = null) * @method Smarty_Internal_TemplateBase setAutoloadFilters(mixed $filters, string $type = null)
* @method Smarty_Internal_TemplateBase addAutoloadFilters(mixed $filters, string $type = null) * @method Smarty_Internal_TemplateBase addAutoloadFilters(mixed $filters, string $type = null)
* @method array getAutoloadFilters(string $type = null) * @method array getAutoloadFilters(string $type = null)
* @local_method Smarty_Internal_TemplateBase registerFilter(string $type, callback $callback, string $name = null) * @local_method Smarty_Internal_TemplateBase registerFilter(string $type, callback $callback, string $name = null)
* @method Smarty_Internal_TemplateBase unregisterFilter(string $type, mixed $callback) * @method Smarty_Internal_TemplateBase unregisterFilter(string $type, mixed $callback)
* @local_method bool loadFilter(string $type, string $name)
* @method Smarty_Internal_TemplateBase unloadFilter(string $type, string $name) * @method Smarty_Internal_TemplateBase unloadFilter(string $type, string $name)
* @method string getDebugTemplate() * @method string getDebugTemplate()
* @method Smarty_Internal_TemplateBase setDebugTemplate(string $tpl_name) * @method Smarty_Internal_TemplateBase setDebugTemplate(string $tpl_name)
@@ -31,11 +31,7 @@
* @method Smarty_Internal_TemplateBase unregisterResource(string $name) * @method Smarty_Internal_TemplateBase unregisterResource(string $name)
* @method Smarty_Internal_TemplateBase registerCacheResource(string $name, Smarty_CacheResource $resource_handler) * @method Smarty_Internal_TemplateBase registerCacheResource(string $name, Smarty_CacheResource $resource_handler)
* @method Smarty_Internal_TemplateBase unregisterCacheResource(string $name) * @method Smarty_Internal_TemplateBase unregisterCacheResource(string $name)
* @local_method Smarty_Internal_TemplateBase registerPlugin(string $type, string $name, callback $callback, bool
* $cacheable = true, mixed $cache_attr = null)
* @method Smarty_Internal_TemplateBase unregisterPlugin(string $type, string $name) * @method Smarty_Internal_TemplateBase unregisterPlugin(string $type, string $name)
* @local_method Smarty_Internal_TemplateBase registerObject(string $object_name, object $object, array
* $allowed_methods_properties = array(), bool $format = true, array $block_methods = array())
* @method Smarty_Internal_TemplateBase unregisterObject(string $object_name) * @method Smarty_Internal_TemplateBase unregisterObject(string $object_name)
* @method object getRegisteredObject(string $object_name) * @method object getRegisteredObject(string $object_name)
* @method Smarty_Internal_TemplateBase registerClass(string $class_name, string $class_impl) * @method Smarty_Internal_TemplateBase registerClass(string $class_name, string $class_impl)
@@ -146,17 +142,19 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
*/ */
private function _execute($template, $cache_id, $compile_id, $parent, $function) private function _execute($template, $cache_id, $compile_id, $parent, $function)
{ {
/* @var Smarty $this ->smarty */
$smarty = $this->_objType == 1 ? $this : $this->smarty; $smarty = $this->_objType == 1 ? $this : $this->smarty;
if ($template === null) { if ($template === null) {
if ($this->_objType != 2) { if ($this->_objType != 2) {
throw new SmartyException($function . '():Missing \'$template\' parameter'); throw new SmartyException($function . '():Missing \'$template\' parameter');
} else { } else {
$template = $this; $template = clone $this;
} }
} elseif (is_object($template)) { } elseif (is_object($template)) {
if (!isset($template->_objType) || $template->_objType != 2) { if (!isset($template->_objType) || $template->_objType != 2) {
throw new SmartyException($function . '():Template object expected'); throw new SmartyException($function . '():Template object expected');
} else {
/* @var Smarty_Internal_Template $template */
$template = clone $template;
} }
} else { } else {
// get template object // get template object
@@ -186,16 +184,11 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
} }
} else { } else {
ob_start(); ob_start();
$save_tpl_vars = $template->tpl_vars;
$save_config_vars = $template->config_vars;
$template->_mergeVars(); $template->_mergeVars();
if (!empty(Smarty::$global_tpl_vars)) { if (!empty(Smarty::$global_tpl_vars)) {
$template->tpl_vars = array_merge(Smarty::$global_tpl_vars, $template->tpl_vars); $template->tpl_vars = array_merge(Smarty::$global_tpl_vars, $template->tpl_vars);
} }
$result = $template->render(false, $function); $result = $template->render(false, $function);
// restore local variables
$template->tpl_vars = $save_tpl_vars;
$template->config_vars = $save_config_vars;
} }
if (isset($_smarty_old_error_level)) { if (isset($_smarty_old_error_level)) {
error_reporting($_smarty_old_error_level); error_reporting($_smarty_old_error_level);

View File

@@ -477,11 +477,11 @@ class Smarty_Internal_TestInstall
'smarty_internal_runtime_getincludepath.php' => true, 'smarty_internal_runtime_getincludepath.php' => true,
'smarty_internal_runtime_hhvm.php' => true, 'smarty_internal_runtime_hhvm.php' => true,
'smarty_internal_runtime_inheritance.php' => true, 'smarty_internal_runtime_inheritance.php' => true,
'smarty_internal_runtime_inline.php' => true,
'smarty_internal_runtime_iscached.php' => true, 'smarty_internal_runtime_iscached.php' => true,
'smarty_internal_runtime_subtemplate.php' => true, 'smarty_internal_runtime_subtemplate.php' => true,
'smarty_internal_runtime_tplfunction.php' => true, 'smarty_internal_runtime_tplfunction.php' => true,
'smarty_internal_runtime_updatecache.php' => true, 'smarty_internal_runtime_updatecache.php' => true,
'smarty_internal_runtime_updatescope.php' => true,
'smarty_internal_runtime_validatecompiled.php' => true, 'smarty_internal_runtime_validatecompiled.php' => true,
'smarty_internal_runtime_var.php' => true, 'smarty_internal_runtime_var.php' => true,
'smarty_internal_runtime_writefile.php' => true, 'smarty_internal_runtime_writefile.php' => true,

View File

@@ -21,25 +21,17 @@ class Smarty_Variable
* @var boolean * @var boolean
*/ */
public $nocache = false; public $nocache = false;
/**
* the scope the variable will have (local,parent or root)
*
* @var int
*/
public $scope = Smarty::SCOPE_LOCAL;
/** /**
* create Smarty variable object * create Smarty variable object
* *
* @param mixed $value the value to assign * @param mixed $value the value to assign
* @param boolean $nocache if true any output of this variable will be not cached * @param boolean $nocache if true any output of this variable will be not cached
* @param int $scope the scope the variable will have (local,parent or root)
*/ */
public function __construct($value = null, $nocache = false, $scope = Smarty::SCOPE_LOCAL) public function __construct($value = null, $nocache = false)
{ {
$this->value = $value; $this->value = $value;
$this->nocache = $nocache; $this->nocache = $nocache;
$this->scope = $scope;
} }
/** /**