mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-07 03:44:26 +02:00
- changed variable scopes to SMARTY_LOCAL_SCOPE, SMARTY_PARENT_SCOPE, SMARTY_ROOT_SCOPE to avoid possible conflicts with user constants
- Smarty variable global attribute replaced with scope attribute
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
04/07/2009
|
||||
- changed variable scopes to SMARTY_LOCAL_SCOPE, SMARTY_PARENT_SCOPE, SMARTY_ROOT_SCOPE to avoid possible conflicts with user constants
|
||||
- Smarty variable global attribute replaced with scope attribute
|
||||
|
||||
04/06/2009
|
||||
- variable scopes LOCAL_SCOPE, PARENT_SCOPE, ROOT_SCOPE
|
||||
- more getter/setter methodes
|
||||
|
@@ -42,9 +42,9 @@ if (!defined('SMARTY_DIR')) {
|
||||
/**
|
||||
* define variable scopes
|
||||
*/
|
||||
define('LOCAL_SCOPE',0);
|
||||
define('PARENT_SCOPE',1);
|
||||
define('ROOT_SCOPE',2);
|
||||
define('SMARTY_LOCAL_SCOPE',0);
|
||||
define('SMARTY_PARENT_SCOPE',1);
|
||||
define('SMARTY_ROOT_SCOPE',2);
|
||||
|
||||
/**
|
||||
* load required base class for creation of the smarty object
|
||||
|
@@ -24,10 +24,10 @@ class Smarty_Internal_Compile_Append extends Smarty_Internal_CompileBase {
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$this->required_attributes = array('var', 'value');
|
||||
$this->optional_attributes = array('global', 'nocache', 'index');
|
||||
$this->optional_attributes = array('scope', 'nocache', 'index');
|
||||
|
||||
$_nocache = 'null';
|
||||
$_global = 'null';
|
||||
$_scope = 'null';
|
||||
// check for nocache attribute before _get_attributes because
|
||||
// it shall not controll caching of the compiled code, but is a parameter
|
||||
if (isset($args['nocache'])) {
|
||||
@@ -40,15 +40,14 @@ class Smarty_Internal_Compile_Append extends Smarty_Internal_CompileBase {
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
|
||||
if (isset($_attr['global']) && $_attr['global'] == 'true') {
|
||||
$_global = 'true';
|
||||
$_global_boolean = true;
|
||||
if (isset($_attr['scope'])) {
|
||||
$_scope = trim($_attr['scope'],'\'');
|
||||
}
|
||||
// compiled output
|
||||
if (isset($_attr['index'])) {
|
||||
return "<?php \$_smarty_tpl->append($_attr[var],array($_attr[index] => $_attr[value]),true,$_nocache,$_global);?>";
|
||||
return "<?php \$_smarty_tpl->append($_attr[var],array($_attr[index] => $_attr[value]),true,$_nocache,$_scope);?>";
|
||||
} else {
|
||||
return "<?php \$_smarty_tpl->append($_attr[var],$_attr[value],false,$_nocache,$_global);?>";
|
||||
return "<?php \$_smarty_tpl->append($_attr[var],$_attr[value],false,$_nocache,$_scope);?>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -24,10 +24,10 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase {
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$this->required_attributes = array('var', 'value');
|
||||
$this->optional_attributes = array('global', 'nocache', 'index');
|
||||
$this->optional_attributes = array('scope', 'nocache', 'index');
|
||||
|
||||
$_nocache = 'null';
|
||||
$_global = 'null';
|
||||
$_scope = 'null';
|
||||
// check for nocache attribute before _get_attributes because
|
||||
// it shall not controll caching of the compiled code, but is a parameter
|
||||
if (isset($args['nocache'])) {
|
||||
@@ -40,22 +40,22 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase {
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
|
||||
if (isset($_attr['global']) && $_attr['global'] == 'true') {
|
||||
$_global = 'true';
|
||||
$_global_boolean = true;
|
||||
if (isset($_attr['scope'])) {
|
||||
$_scope = trim($_attr['scope'],'\'');
|
||||
}
|
||||
|
||||
if (isset($_attr['index'])) {
|
||||
$_index = $_attr['index'];
|
||||
}
|
||||
// compiled output
|
||||
if (isset($_attr['index'])) {
|
||||
if ($_attr['index'] == '') {
|
||||
return "<?php \$_smarty_tpl->append($_attr[var],$_attr[value],false,$_nocache,$_global);?>";
|
||||
return "<?php \$_smarty_tpl->append($_attr[var],$_attr[value],false,$_nocache,$_scope);?>";
|
||||
} else {
|
||||
return "<?php \$_tmp$_attr[index] = $_attr[value]; \$_smarty_tpl->append($_attr[var],\$_tmp,true,$_nocache,$_global);?>";
|
||||
return "<?php \$_tmp$_attr[index] = $_attr[value]; \$_smarty_tpl->append($_attr[var],\$_tmp,true,$_nocache,$_scope);?>";
|
||||
}
|
||||
} else {
|
||||
return "<?php \$_smarty_tpl->assign($_attr[var],$_attr[value],$_nocache,$_global);?>";
|
||||
return "<?php \$_smarty_tpl->assign($_attr[var],$_attr[value],$_nocache,$_scope);?>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -34,12 +34,12 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase {
|
||||
$_assign = $_attr['assign'];
|
||||
}
|
||||
|
||||
$_parent_scope = LOCAL_SCOPE;
|
||||
$_parent_scope = SMARTY_LOCAL_SCOPE;
|
||||
if (isset($_attr['scope'])) {
|
||||
if ($_attr['scope'] == '\'parent\'') {
|
||||
$_parent_scope = PARENT_SCOPE;
|
||||
$_parent_scope = SMARTY_PARENT_SCOPE;
|
||||
} elseif ($_attr['scope'] == '\'root\'') {
|
||||
$_parent_scope = ROOT_SCOPE;
|
||||
$_parent_scope = SMARTY_ROOT_SCOPE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase {
|
||||
unset($_attr['file'], $_attr['assign'], $_attr['caching_lifetime'], $_attr['nocache'], $_attr['caching'], $_attr['scope']);
|
||||
// remaining attributes must be assigned as smarty variable
|
||||
if (!empty($_attr)) {
|
||||
if ($_parent_scope == LOCAL_SCOPE) {
|
||||
if ($_parent_scope == SMARTY_LOCAL_SCOPE) {
|
||||
// create variables
|
||||
foreach ($_attr as $_key => $_value) {
|
||||
$_output .= "\$_template->assign('$_key',$_value);";
|
||||
|
@@ -89,7 +89,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
$this->caching_type = $this->smarty->default_caching_type;
|
||||
$this->security = $this->smarty->security;
|
||||
$this->cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($this->caching_type);
|
||||
$this->parent = $_parent;
|
||||
$this->parent = $_parent;
|
||||
$this->tpl_vars['smarty'] = new Smarty_Variable;
|
||||
// load filter handler if required
|
||||
if (!is_object($this->smarty->filter_handler) && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) {
|
||||
$this->smarty->loadPlugin('Smarty_Internal_Run_Filter');
|
||||
@@ -546,11 +547,11 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
/**
|
||||
* Update Smarty variables in parent variable object
|
||||
*/
|
||||
public function updateParentVariables ($scope = LOCAL_SCOPE)
|
||||
public function updateParentVariables ($scope = SMARTY_LOCAL_SCOPE)
|
||||
{
|
||||
foreach ($this->tpl_vars as $_key => $_value) {
|
||||
// copy global vars back to parent
|
||||
if (isset($this->parent) && ($scope == PARENT_SCOPE || $this->tpl_vars[$_key]->global)) {
|
||||
if (isset($this->parent) && ($scope == SMARTY_PARENT_SCOPE || $this->tpl_vars[$_key]->scope == SMARTY_PARENT_SCOPE)) {
|
||||
if (isset($this->parent->tpl_vars[$_key])) {
|
||||
// variable is already defined in parent, copy value
|
||||
$this->parent->tpl_vars[$_key]->value = $this->tpl_vars[$_key]->value;
|
||||
@@ -559,7 +560,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
$this->parent->tpl_vars[$_key] = clone $_value;
|
||||
}
|
||||
}
|
||||
if ($scope == ROOT_SCOPE) {
|
||||
if ($scope == SMARTY_ROOT_SCOPE || $this->tpl_vars[$_key]->scope == SMARTY_ROOT_SCOPE) {
|
||||
if (isset($this->smarty->tpl_vars[$_key])) {
|
||||
// variable is already defined in root, copy value
|
||||
$this->smarty->tpl_vars[$_key]->value = $this->tpl_vars[$_key]->value;
|
||||
|
@@ -20,21 +20,21 @@ class Smarty_Internal_TemplateBase {
|
||||
* @param array $ |string $tpl_var the template variable name(s)
|
||||
* @param mixed $value the value to assign
|
||||
* @param boolean $nocache if true any output of this variable will be not cached
|
||||
* @param boolean $global if true the variable will have global scope
|
||||
* @param boolean $scope the scope the variable will have (local,parent or root)
|
||||
*/
|
||||
public function assign($tpl_var, $value = null, $nocache = false, $global = false)
|
||||
public function assign($tpl_var, $value = null, $nocache = false, $scope = SMARTY_LOCAL_SCOPE)
|
||||
{
|
||||
if (is_array($tpl_var)) {
|
||||
foreach ($tpl_var as $_key => $_val) {
|
||||
if ($_key != '') {
|
||||
$this->check_tplvar($_key);
|
||||
$this->tpl_vars[$_key] = new Smarty_variable($_val, $nocache, $global);
|
||||
$this->tpl_vars[$_key] = new Smarty_variable($_val, $nocache, $scope);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($tpl_var != '') {
|
||||
$this->check_tplvar($tpl_var);
|
||||
$this->tpl_vars[$tpl_var] = new Smarty_variable($value, $nocache, $global);
|
||||
$this->tpl_vars[$tpl_var] = new Smarty_variable($value, $nocache, $scope);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,13 +59,13 @@ class Smarty_Internal_TemplateBase {
|
||||
* @param string $tpl_var the template variable name
|
||||
* @param mixed $ &$value the referenced value to assign
|
||||
* @param boolean $nocache if true any output of this variable will be not cached
|
||||
* @param boolean $global if true the variable will have global scope
|
||||
* @param boolean $scope the scope the variable will have (local,parent or root)
|
||||
*/
|
||||
public function assign_by_ref($tpl_var, &$value, $nocache = false, $global = false)
|
||||
public function assign_by_ref($tpl_var, &$value, $nocache = false, $scope = SMARTY_LOCAL_SCOPE)
|
||||
{
|
||||
if ($tpl_var != '') {
|
||||
$this->check_tplvar($tpl_var);
|
||||
$this->tpl_vars[$tpl_var] = new Smarty_variable(null, $nocache, $global);
|
||||
$this->tpl_vars[$tpl_var] = new Smarty_variable(null, $nocache, $scope);
|
||||
$this->tpl_vars[$tpl_var]->value = &$value;
|
||||
}
|
||||
}
|
||||
@@ -75,8 +75,10 @@ class Smarty_Internal_TemplateBase {
|
||||
* @param array $ |string $tpl_var the template variable name(s)
|
||||
* @param mixed $value the value to append
|
||||
* @param boolean $merge flag if array elements shall be merged
|
||||
* @param boolean $nocache if true any output of this variable will be not cached
|
||||
* @param boolean $scope the scope the variable will have (local,parent or root)
|
||||
*/
|
||||
public function append($tpl_var, $value = null, $merge = false, $nocache = false, $global = false)
|
||||
public function append($tpl_var, $value = null, $merge = false, $nocache = false, $scope = SMARTY_LOCAL_SCOPE)
|
||||
{
|
||||
if (is_array($tpl_var)) {
|
||||
// $tpl_var is an array, ignore $value
|
||||
@@ -84,7 +86,7 @@ class Smarty_Internal_TemplateBase {
|
||||
if ($_key != '') {
|
||||
if (!isset($this->tpl_vars[$_key])) {
|
||||
$this->check_tplvar($_key);
|
||||
$this->tpl_vars[$_key] = new Smarty_variable(null, $nocache, $global);
|
||||
$this->tpl_vars[$_key] = new Smarty_variable(null, $nocache, $scope);
|
||||
}
|
||||
if (!is_array($this->tpl_vars[$_key]->value)) {
|
||||
settype($this->tpl_vars[$_key]->value, 'array');
|
||||
@@ -102,7 +104,7 @@ class Smarty_Internal_TemplateBase {
|
||||
if ($tpl_var != '' && isset($value)) {
|
||||
if (!isset($this->tpl_vars[$tpl_var])) {
|
||||
$this->check_tplvar($tpl_var);
|
||||
$this->tpl_vars[$tpl_var] = new Smarty_variable(null, $nocache, $global);
|
||||
$this->tpl_vars[$tpl_var] = new Smarty_variable(null, $nocache, $scope);
|
||||
}
|
||||
if (!is_array($this->tpl_vars[$tpl_var]->value)) {
|
||||
settype($this->tpl_vars[$tpl_var]->value, 'array');
|
||||
@@ -349,19 +351,19 @@ class Smarty_Variable {
|
||||
// template variable
|
||||
public $value;
|
||||
public $nocache;
|
||||
public $global;
|
||||
public $scope;
|
||||
/**
|
||||
* create Smarty variable object
|
||||
*
|
||||
* @param mixed $value the value to assign
|
||||
* @param boolean $nocache if true any output of this variable will be not cached
|
||||
* @param boolean $global if true the variable will have global scope
|
||||
* @param boolean $scope the scope the variable will have (local,parent or root)
|
||||
*/
|
||||
public function __construct ($value = null, $nocache = false, $global = false)
|
||||
public function __construct ($value = null, $nocache = false, $scope = SMARTY_LOCAL_SCOPE)
|
||||
{
|
||||
$this->value = $value;
|
||||
$this->nocache = $nocache;
|
||||
$this->global = $global;
|
||||
$this->scope = $scope;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user