Files
smarty/libs/sysplugins/smarty_internal_runtime_updatescope.php

75 lines
2.6 KiB
PHP
Raw Normal View History

2015-10-29 22:33:00 +01:00
<?php
/**
* Runtime Extension updateScope
2015-10-29 22:33:00 +01:00
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*
**/
class Smarty_Internal_Runtime_UpdateScope
{
/**
* Update new assigned template variable in other effected scopes
*
* @param \Smarty_Internal_Data $tpl data object
* @param string $varName variable name
* @param int $scope scope to which bubble up variable value
2015-10-29 22:33:00 +01:00
*/
public function updateScope(Smarty_Internal_Data $tpl, $varName, $scope = Smarty::SCOPE_LOCAL)
2015-10-29 22:33:00 +01:00
{
$scopes = array();
if ($scope) {
$scopes[] = $scope;
}
if ($tpl->scope) {
$scopes[] = $tpl->scope;
}
if (empty($scopes)) {
2015-10-29 22:33:00 +01:00
return;
}
/* @var Smarty_Internal_Data $ptr */
$ptr = null;
foreach ($scopes as $s) {
2015-10-29 22:33:00 +01:00
$s = ($bubble_up = $s >= Smarty::SCOPE_BUBBLE_UP) ? $s - Smarty::SCOPE_BUBBLE_UP : $s;
if ($bubble_up && $s) {
2016-01-02 02:47:32 +01:00
$oldGlobal = null;
if ($s == Smarty::SCOPE_GLOBAL) {
$oldGlobal =
isset(Smarty::$global_tpl_vars[ $varName ]) ? Smarty::$global_tpl_vars[ $varName ] : null;
Smarty::$global_tpl_vars[ $varName ] = $tpl->tpl_vars[ $varName ];
}
if (isset($tpl->parent) && $tpl->parent->_objType == 2) {
$ptr = $tpl->parent;
2016-01-02 02:47:32 +01:00
if ($s == Smarty::SCOPE_GLOBAL && isset($oldGlobal) && isset($ptr->tpl_vars[ $varName ]) &&
$ptr->tpl_vars[ $varName ] !== $oldGlobal
) {
continue;
}
$ptr->tpl_vars[ $varName ] = $tpl->tpl_vars[ $varName ];
if (isset($ptr->parent)) {
$ptr = $ptr->parent;
}
2016-01-02 02:47:32 +01:00
} elseif (isset($tpl->parent)) {
$ptr = $tpl->parent;
2015-10-29 22:33:00 +01:00
}
if ($s == Smarty::SCOPE_PARENT) {
continue;
}
while (isset($ptr) && $ptr->_objType == 2) {
$ptr->tpl_vars[ $varName ] = $tpl->tpl_vars[ $varName ];
2015-10-29 22:33:00 +01:00
$ptr = $ptr->parent;
}
if ($s == Smarty::SCOPE_TPL_ROOT) {
continue;
2016-01-02 02:47:32 +01:00
}
while (isset($ptr) && $s != Smarty::SCOPE_GLOBAL) {
$ptr->tpl_vars[ $varName ] = $tpl->tpl_vars[ $varName ];
2016-01-02 02:47:32 +01:00
$ptr = isset($ptr->parent) ? $ptr->parent : null;
2015-10-29 22:33:00 +01:00
}
}
}
}
}