mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
- update scope handling
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
===== 3.1.30-dev ===== (xx.xx.xx)
|
===== 3.1.30-dev ===== (xx.xx.xx)
|
||||||
|
02.01.2016
|
||||||
|
- update scope handling
|
||||||
|
|
||||||
01.01.2016
|
01.01.2016
|
||||||
- remove Smarty::$resource_cache_mode property
|
- remove Smarty::$resource_cache_mode property
|
||||||
|
|
||||||
|
@@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
/**
|
/**
|
||||||
* smarty version
|
* smarty version
|
||||||
*/
|
*/
|
||||||
const SMARTY_VERSION = '3.1.30-dev/15';
|
const SMARTY_VERSION = '3.1.30-dev/16';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* define variable scopes
|
* define variable scopes
|
||||||
@@ -134,8 +134,6 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
|
|
||||||
const SCOPE_ROOT = 8;
|
const SCOPE_ROOT = 8;
|
||||||
|
|
||||||
const SCOPE_SMARTY = 16;
|
|
||||||
|
|
||||||
const SCOPE_GLOBAL = 32;
|
const SCOPE_GLOBAL = 32;
|
||||||
|
|
||||||
const SCOPE_BUBBLE_UP = 64;
|
const SCOPE_BUBBLE_UP = 64;
|
||||||
|
@@ -22,7 +22,7 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'global' => true,
|
public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'global' => true,
|
||||||
'smarty' => true, 'tpl_root' => true);
|
'tpl_root' => true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compiles code for the {assign} tag
|
* Compiles code for the {assign} tag
|
||||||
@@ -68,8 +68,6 @@ 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') {
|
} elseif ($_attr[ 'scope' ] == 'tpl_root') {
|
||||||
$_scope = Smarty::SCOPE_TPL_ROOT;
|
$_scope = Smarty::SCOPE_TPL_ROOT;
|
||||||
}
|
}
|
||||||
|
@@ -45,8 +45,8 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'global' => true,
|
public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true,
|
||||||
'smarty' => true, 'tpl_root' => true);
|
'tpl_root' => true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compiles code for the {config_load} tag
|
* Compiles code for the {config_load} tag
|
||||||
@@ -84,10 +84,6 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
|
|||||||
$_scope = Smarty::SCOPE_PARENT;
|
$_scope = Smarty::SCOPE_PARENT;
|
||||||
} elseif ($_attr['scope'] == 'root') {
|
} elseif ($_attr['scope'] == 'root') {
|
||||||
$_scope = Smarty::SCOPE_ROOT;
|
$_scope = Smarty::SCOPE_ROOT;
|
||||||
} elseif ($_attr['scope'] == 'global') {
|
|
||||||
$_scope = Smarty::SCOPE_GLOBAL;
|
|
||||||
} elseif ($_attr['scope'] == 'smarty') {
|
|
||||||
$_scope = Smarty::SCOPE_SMARTY;
|
|
||||||
} elseif ($_attr['scope'] == 'tpl_root') {
|
} elseif ($_attr['scope'] == 'tpl_root') {
|
||||||
$_scope = Smarty::SCOPE_TPL_ROOT;
|
$_scope = Smarty::SCOPE_TPL_ROOT;
|
||||||
}
|
}
|
||||||
|
@@ -58,8 +58,8 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'global' => true,
|
public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true,
|
||||||
'smarty' => true, 'tpl_root' => true);
|
'tpl_root' => true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compiles code for the {include} tag
|
* Compiles code for the {include} tag
|
||||||
@@ -124,16 +124,11 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
|||||||
$_scope = Smarty::SCOPE_PARENT;
|
$_scope = Smarty::SCOPE_PARENT;
|
||||||
} elseif ($_attr['scope'] == 'root') {
|
} elseif ($_attr['scope'] == 'root') {
|
||||||
$_scope = Smarty::SCOPE_ROOT;
|
$_scope = Smarty::SCOPE_ROOT;
|
||||||
} elseif ($_attr['scope'] == 'global') {
|
|
||||||
$_scope = Smarty::SCOPE_GLOBAL;
|
|
||||||
} elseif ($_attr['scope'] == 'smarty') {
|
|
||||||
$_scope = Smarty::SCOPE_SMARTY;
|
|
||||||
} elseif ($_attr['scope'] == 'tpl_root') {
|
} elseif ($_attr['scope'] == 'tpl_root') {
|
||||||
$_scope = Smarty::SCOPE_TPL_ROOT;
|
$_scope = Smarty::SCOPE_TPL_ROOT;
|
||||||
}
|
}
|
||||||
if ($_attr['bubble_up'] === true) {
|
$_scope += (isset($_attr[ 'bubble_up' ]) && $_attr[ 'bubble_up' ] == 'false') ? 0 :
|
||||||
$_scope = $_scope + Smarty::SCOPE_BUBBLE_UP;
|
Smarty::SCOPE_BUBBLE_UP;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -83,10 +83,17 @@ class Smarty_Internal_Method_ConfigLoad
|
|||||||
{
|
{
|
||||||
$this->_assignConfigVars($tpl->parent, $tpl, $_config_vars);
|
$this->_assignConfigVars($tpl->parent, $tpl, $_config_vars);
|
||||||
$scope = $tpl->source->scope;
|
$scope = $tpl->source->scope;
|
||||||
if (!$scope && !$tpl->scope) {
|
$scopes = array();
|
||||||
|
if ($scope) {
|
||||||
|
$scopes[] = $scope;
|
||||||
|
}
|
||||||
|
if ($tpl->scope) {
|
||||||
|
$scopes[] = $tpl->scope;
|
||||||
|
}
|
||||||
|
if (empty($scopes)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
foreach (array($scope, $tpl->scope) as $s) {
|
foreach ($scopes as $s) {
|
||||||
$s = ($bubble_up = $s >= Smarty::SCOPE_BUBBLE_UP) ? $s - Smarty::SCOPE_BUBBLE_UP : $s;
|
$s = ($bubble_up = $s >= Smarty::SCOPE_BUBBLE_UP) ? $s - Smarty::SCOPE_BUBBLE_UP : $s;
|
||||||
if ($bubble_up && $s) {
|
if ($bubble_up && $s) {
|
||||||
$ptr = $tpl->parent->parent;
|
$ptr = $tpl->parent->parent;
|
||||||
@@ -103,19 +110,15 @@ class Smarty_Internal_Method_ConfigLoad
|
|||||||
}
|
}
|
||||||
if ($s == Smarty::SCOPE_TPL_ROOT) {
|
if ($s == Smarty::SCOPE_TPL_ROOT) {
|
||||||
continue;
|
continue;
|
||||||
} elseif ($s == Smarty::SCOPE_SMARTY) {
|
|
||||||
$this->_assignConfigVars($tpl->smarty, $tpl, $_config_vars);
|
|
||||||
} elseif ($s == Smarty::SCOPE_GLOBAL) {
|
|
||||||
$this->_assignConfigVars($tpl->smarty, $tpl, $_config_vars);
|
|
||||||
} elseif ($s == Smarty::SCOPE_ROOT) {
|
} elseif ($s == Smarty::SCOPE_ROOT) {
|
||||||
while (isset($ptr->parent)) {
|
while (isset($ptr->parent)) {
|
||||||
$ptr = $ptr->parent;
|
$ptr = $ptr->parent;
|
||||||
}
|
|
||||||
$this->_assignConfigVars($ptr, $tpl, $_config_vars);
|
$this->_assignConfigVars($ptr, $tpl, $_config_vars);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assign all config variables in given scope
|
* Assign all config variables in given scope
|
||||||
|
@@ -34,12 +34,25 @@ class Smarty_Internal_Runtime_UpdateScope
|
|||||||
foreach ($scopes as $s) {
|
foreach ($scopes as $s) {
|
||||||
$s = ($bubble_up = $s >= Smarty::SCOPE_BUBBLE_UP) ? $s - Smarty::SCOPE_BUBBLE_UP : $s;
|
$s = ($bubble_up = $s >= Smarty::SCOPE_BUBBLE_UP) ? $s - Smarty::SCOPE_BUBBLE_UP : $s;
|
||||||
if ($bubble_up && $s) {
|
if ($bubble_up && $s) {
|
||||||
if (isset($tpl->parent)) {
|
$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;
|
$ptr = $tpl->parent;
|
||||||
|
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 ];
|
$ptr->tpl_vars[ $varName ] = $tpl->tpl_vars[ $varName ];
|
||||||
if (isset($ptr->parent)) {
|
if (isset($ptr->parent)) {
|
||||||
$ptr = $ptr->parent;
|
$ptr = $ptr->parent;
|
||||||
}
|
}
|
||||||
|
} elseif (isset($tpl->parent)) {
|
||||||
|
$ptr = $tpl->parent;
|
||||||
}
|
}
|
||||||
if ($s == Smarty::SCOPE_PARENT) {
|
if ($s == Smarty::SCOPE_PARENT) {
|
||||||
continue;
|
continue;
|
||||||
@@ -50,15 +63,10 @@ class Smarty_Internal_Runtime_UpdateScope
|
|||||||
}
|
}
|
||||||
if ($s == Smarty::SCOPE_TPL_ROOT) {
|
if ($s == Smarty::SCOPE_TPL_ROOT) {
|
||||||
continue;
|
continue;
|
||||||
} elseif ($s == Smarty::SCOPE_SMARTY) {
|
|
||||||
$tpl->smarty->tpl_vars[ $varName ] = $tpl->tpl_vars[ $varName ];
|
|
||||||
} elseif ($s == Smarty::SCOPE_GLOBAL) {
|
|
||||||
Smarty::$global_tpl_vars[ $varName ] = $tpl->tpl_vars[ $varName ];
|
|
||||||
} elseif ($s == Smarty::SCOPE_ROOT) {
|
|
||||||
while (isset($ptr->parent)) {
|
|
||||||
$ptr = $ptr->parent;
|
|
||||||
}
|
}
|
||||||
|
while (isset($ptr) && $s != Smarty::SCOPE_GLOBAL) {
|
||||||
$ptr->tpl_vars[ $varName ] = $tpl->tpl_vars[ $varName ];
|
$ptr->tpl_vars[ $varName ] = $tpl->tpl_vars[ $varName ];
|
||||||
|
$ptr = isset($ptr->parent) ? $ptr->parent : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -204,7 +204,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
}
|
}
|
||||||
if (!$no_output_filter &&
|
if (!$no_output_filter &&
|
||||||
(!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled) &&
|
(!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled) &&
|
||||||
(isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))
|
(isset($this->smarty->autoload_filters[ 'output' ]) ||
|
||||||
|
isset($this->smarty->registered_filters[ 'output' ]))
|
||||||
) {
|
) {
|
||||||
return $this->smarty->ext->_filterHandler->runFilter('output', ob_get_clean(), $this);
|
return $this->smarty->ext->_filterHandler->runFilter('output', ob_get_clean(), $this);
|
||||||
}
|
}
|
||||||
@@ -295,16 +296,10 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
// set template scope
|
// set template scope
|
||||||
$tpl->scope = $scope;
|
$tpl->scope = $scope;
|
||||||
$scopePtr = false;
|
$scopePtr = false;
|
||||||
if ($scope & ~Smarty::SCOPE_BUBBLE_UP) {
|
$scope = $scope & ~Smarty::SCOPE_BUBBLE_UP;
|
||||||
if ($scope == Smarty::SCOPE_GLOBAL) {
|
if ($scope) {
|
||||||
$tpl->tpl_vars = Smarty::$global_tpl_vars;
|
|
||||||
$tpl->config_vars = $tpl->smarty->config_vars;
|
|
||||||
$scopePtr = true;
|
|
||||||
} else {
|
|
||||||
if ($scope == Smarty::SCOPE_PARENT) {
|
if ($scope == Smarty::SCOPE_PARENT) {
|
||||||
$scopePtr = $this;
|
$scopePtr = $this;
|
||||||
} elseif ($scope == Smarty::SCOPE_SMARTY) {
|
|
||||||
$scopePtr = $tpl->smarty;
|
|
||||||
} else {
|
} else {
|
||||||
$scopePtr = $tpl;
|
$scopePtr = $tpl;
|
||||||
while (isset($scopePtr->parent)) {
|
while (isset($scopePtr->parent)) {
|
||||||
@@ -317,8 +312,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
$tpl->tpl_vars = $scopePtr->tpl_vars;
|
$tpl->tpl_vars = $scopePtr->tpl_vars;
|
||||||
$tpl->config_vars = $scopePtr->config_vars;
|
$tpl->config_vars = $scopePtr->config_vars;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($tpl->smarty->_cache[ 'tplObjects' ][ $tpl->templateId ]) && !$tpl->source->handler->recompiled) {
|
if (!isset($tpl->smarty->_cache[ 'tplObjects' ][ $tpl->templateId ]) && !$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 ||
|
||||||
@@ -326,7 +319,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
$tpl->smarty->_cache[ 'subTplInfo' ][ $tpl->template_resource ] > 1);
|
$tpl->smarty->_cache[ 'subTplInfo' ][ $tpl->template_resource ] > 1);
|
||||||
// check if template object should be cached
|
// check if template object should be cached
|
||||||
if ($tpl->_isParentTemplate() && isset($tpl->smarty->_cache[ 'tplObjects' ][ $tpl->parent->templateId ]) ||
|
if ($tpl->_isParentTemplate() && isset($tpl->smarty->_cache[ 'tplObjects' ][ $tpl->parent->templateId ]) ||
|
||||||
$forceTplCache) {
|
$forceTplCache
|
||||||
|
) {
|
||||||
$tpl->smarty->_cache[ 'tplObjects' ][ $tpl->templateId ] = $tpl;
|
$tpl->smarty->_cache[ 'tplObjects' ][ $tpl->templateId ] = $tpl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -358,15 +352,10 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($scopePtr) {
|
if ($scopePtr) {
|
||||||
if ($scope == Smarty::SCOPE_GLOBAL) {
|
|
||||||
Smarty::$global_tpl_vars = $tpl->tpl_vars;
|
|
||||||
$tpl->smarty->config_vars = $tpl->config_vars;
|
|
||||||
} else {
|
|
||||||
$scopePtr->tpl_vars = $tpl->tpl_vars;
|
$scopePtr->tpl_vars = $tpl->tpl_vars;
|
||||||
$scopePtr->config_vars = $tpl->config_vars;
|
$scopePtr->config_vars = $tpl->config_vars;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get called sub-templates and save call count
|
* Get called sub-templates and save call count
|
||||||
@@ -461,7 +450,9 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
) {
|
) {
|
||||||
// check file dependencies at compiled code
|
// check file dependencies at compiled code
|
||||||
foreach ($properties[ 'file_dependency' ] as $_file_to_check) {
|
foreach ($properties[ 'file_dependency' ] as $_file_to_check) {
|
||||||
if ($_file_to_check[2] == 'file' || $_file_to_check[2] == 'extends' || $_file_to_check[2] == 'php') {
|
if ($_file_to_check[ 2 ] == 'file' || $_file_to_check[ 2 ] == 'extends' ||
|
||||||
|
$_file_to_check[ 2 ] == 'php'
|
||||||
|
) {
|
||||||
if ($tpl->source->filepath == $_file_to_check[ 0 ]) {
|
if ($tpl->source->filepath == $_file_to_check[ 0 ]) {
|
||||||
// do not recheck current template
|
// do not recheck current template
|
||||||
continue;
|
continue;
|
||||||
@@ -514,7 +505,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
return $is_valid && !function_exists($properties[ 'unifunc' ]);
|
return $is_valid && !function_exists($properties[ 'unifunc' ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compiles the template
|
* Compiles the template
|
||||||
* If the template is not evaluated the compiled template is saved on disk
|
* If the template is not evaluated the compiled template is saved on disk
|
||||||
|
Reference in New Issue
Block a user