4 * Runtime Extension updateScope
7 * @subpackage PluginsInternal
11 class Smarty_Internal_Runtime_UpdateScope
15 * Update new assigned template or config variable in other effected scopes
17 * @param Smarty_Internal_Template $tpl data object
18 * @param string|null $varName variable name
19 * @param int $tagScope tag scope to which bubble up variable value
22 public function _updateScope(Smarty_Internal_Template $tpl, $varName, $tagScope = 0)
25 $this->_updateVarStack($tpl, $varName);
26 $tagScope = $tagScope & ~Smarty::SCOPE_LOCAL;
27 if (!$tpl->scope && !$tagScope) return;
29 $mergedScope = $tagScope | $tpl->scope;
31 if ($mergedScope & Smarty::SCOPE_GLOBAL && $varName) {
32 Smarty::$global_tpl_vars[ $varName ] = $tpl->tpl_vars[ $varName ];
35 foreach ($this->_getAffectedScopes($tpl, $mergedScope) as $ptr) {
36 $this->_updateVariableInOtherScope($ptr->tpl_vars, $tpl, $varName);
37 if($tagScope && $ptr->_isTplObj() && isset($tpl->_cache[ 'varStack' ])) {
38 $this->_updateVarStack($ptr, $varName); }
44 * Get array of objects which needs to be updated by given scope value
46 * @param Smarty_Internal_Template $tpl
47 * @param int $mergedScope merged tag and template scope to which bubble up variable value
51 public function _getAffectedScopes(Smarty_Internal_Template $tpl, $mergedScope)
55 if ($mergedScope && isset($ptr) && $ptr->_isTplObj()) {
57 $mergedScope = $mergedScope & ~Smarty::SCOPE_PARENT;
59 // only parent was set, we are done
64 while (isset($ptr) && $ptr->_isTplObj()) {
68 if ($mergedScope & Smarty::SCOPE_SMARTY) {
69 if (isset($tpl->smarty)) {
70 $_stack[] = $tpl->smarty;
72 } elseif ($mergedScope & Smarty::SCOPE_ROOT) {
74 if (!$ptr->_isTplObj()) {
85 * Update varibale in other scope
87 * @param array $tpl_vars template variable array
88 * @param \Smarty_Internal_Template $from
89 * @param string $varName variable name
91 public function _updateVariableInOtherScope(&$tpl_vars, Smarty_Internal_Template $from, $varName)
93 if (!isset($tpl_vars[ $varName ])) {
94 $tpl_vars[ $varName ] = clone $from->tpl_vars[ $varName ];
96 $tpl_vars[ $varName ] = clone $tpl_vars[ $varName ];
97 $tpl_vars[ $varName ]->value = $from->tpl_vars[ $varName ]->value;
102 * Update variable in template local variable stack
104 * @param \Smarty_Internal_Template $tpl
105 * @param string|null $varName variable name or null for config variables
107 public function _updateVarStack(Smarty_Internal_Template $tpl, $varName)
110 while (isset($tpl->_cache[ 'varStack' ][ $i ])) {
111 $this->_updateVariableInOtherScope($tpl->_cache[ 'varStack' ][ $i ][ 'tpl' ], $tpl, $varName);