- variable scopes LOCAL_SCOPE, PARENT_SCOPE, ROOT_SCOPE

- more getter/setter methodes
This commit is contained in:
Uwe.Tews
2009-04-06 02:53:09 +00:00
parent 65f1871c98
commit 0ab30877db
36 changed files with 331 additions and 48 deletions

2
README
View File

@@ -104,7 +104,7 @@ $smarty->display('string:This is my template, {$foo}!');
You can use complex expressions almost anywhere.
{$x+$y} will output the sum of x and y.
PHP functions can be used in expressions unless they are not disabled by the security policy.
PHP functions can be used in expressions unless they are disabled by the security policy.
{assign var=foo value=2*(3+sqrt($bar))}
You can define arrays.

View File

@@ -1,3 +1,7 @@
04/06/2009
- variable scopes LOCAL_SCOPE, PARENT_SCOPE, ROOT_SCOPE
- more getter/setter methodes
04/05/2009
- replaced new array looping syntax {for $foo in $array} with {foreach $foo in $array} to avoid confusion
- added append array for short form of assign {$foo[]='bar'} and allow assignments to nested arrays {$foo['bla']['blue']='bar'}

View File

@@ -35,10 +35,16 @@
* if not defined, include_path will be used. Sets SMARTY_DIR only if user
* application has not already defined it.
*/
if (!defined('SMARTY_DIR')) {
define('SMARTY_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
}
}
/**
* define variable scopes
*/
define('LOCAL_SCOPE',0);
define('PARENT_SCOPE',1);
define('ROOT_SCOPE',2);
/**
* load required base class for creation of the smarty object

View File

@@ -34,12 +34,12 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase {
$_assign = $_attr['assign'];
}
$_parent_scope = '0';
$_parent_scope = LOCAL_SCOPE;
if (isset($_attr['scope'])) {
if ($_attr['scope'] == '\'parent\'') {
$_parent_scope = '1';
$_parent_scope = PARENT_SCOPE;
} elseif ($_attr['scope'] == '\'root\'') {
$_parent_scope = '2';
$_parent_scope = ROOT_SCOPE;
}
}
@@ -69,13 +69,13 @@ 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 == '0') {
if ($_parent_scope == LOCAL_SCOPE) {
// create variables
foreach ($_attr as $_key => $_value) {
$_output .= "\$_template->assign('$_key',$_value);";
}
} else {
$this->compiler->trigger_template_error('variable passing not allowed in parent scope');
$this->compiler->trigger_template_error('variable passing not allowed in parent/global scope');
}
}
// add caching parameter if required

View File

@@ -387,9 +387,9 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
// disable caching for evaluated code
if ($this->isEvaluated()) {
$this->caching = false;
}
// checks if template exists
$this->getTemplateFilepath();
}
// checks if template exists
$this->getTemplateFilepath();
// read from cache or render
if ($this->rendered_content === null && !$this->isCached()) {
// render template (not loaded and not in cache)
@@ -546,25 +546,26 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
/**
* Update Smarty variables in parent variable object
*/
public function updateParentVariables ($mode = 0)
{
// do we have a back pointer?
if (is_object($this->parent)) {
if ($mode == 2) {
$_ptr = $this->smarty;
} else {
$_ptr = $this->parent;
public function updateParentVariables ($scope = 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->tpl_vars[$_key])) {
// variable is already defined in parent, copy value
$this->parent->tpl_vars[$_key]->value = $this->tpl_vars[$_key]->value;
} else {
// create variable in parent
$this->parent->tpl_vars[$_key] = clone $_value;
}
}
foreach ($this->tpl_vars as $_key => $_value) {
// copy global vars back to parent
if ($mode > 0 || $this->tpl_vars[$_key]->global) {
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;
} else {
// create variable in parent
$this->parent->tpl_vars[$_key] = clone $_value;
}
if ($scope == 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;
} else {
// create variable in root
$this->smarty->tpl_vars[$_key] = clone $_value;
}
}
}

View File

@@ -18,7 +18,8 @@
class Smarty_Method_disableCacheModifyCheck extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->cache_modified_check = false;
$this->smarty->cache_modified_check = false;
return ;
}
}

View File

@@ -18,7 +18,8 @@
class Smarty_Method_DisableCaching extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->caching = false;
$this->smarty->caching = false;
return;
}
}

View File

@@ -18,7 +18,8 @@
class Smarty_Method_DisableCompileCheck extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->compile_check = false;
$this->smarty->compile_check = false;
return;
}
}

View File

@@ -18,7 +18,8 @@
class Smarty_Method_disableConfigBooleanize extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->config_booleanize = false;
$this->smarty->config_booleanize = false;
return;
}
}

View File

@@ -18,7 +18,8 @@
class Smarty_Method_disableConfigOverwrite extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->config_overwrite = false;
$this->smarty->config_overwrite = false;
return ;
}
}

View File

@@ -18,7 +18,8 @@
class Smarty_Method_disableConfigReadHidden extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->config_read_hidden = false;
$this->smarty->config_read_hidden = false;
return;
}
}

View File

@@ -18,7 +18,8 @@
class Smarty_Method_DisableDebugging extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->debugging = false;
$this->smarty->debugging = false;
return;
}
}

View File

@@ -18,7 +18,8 @@
class Smarty_Method_disableDebuggingUrlCtrl extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->debugging_ctrl = 'none';
$this->smarty->debugging_ctrl = 'none';
return;
}
}

View File

@@ -18,7 +18,8 @@
class Smarty_Method_disableDefaultTimezone extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->set_timezone = false;
$this->smarty->set_timezone = false;
return;
}
}

View File

@@ -18,7 +18,8 @@
class Smarty_Method_DisableForceCompile extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->force_compile = false;
$this->smarty->force_compile = false;
return;
}
}

View File

@@ -18,7 +18,8 @@
class Smarty_Method_enableCacheModifyCheck extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->cache_modified_check = true;
$this->smarty->cache_modified_check = true;
return;
}
}

View File

@@ -18,7 +18,8 @@
class Smarty_Method_EnableCompileCheck extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->compile_check = true;
$this->smarty->compile_check = true;
return;
}
}

View File

@@ -18,7 +18,8 @@
class Smarty_Method_enableConfigBooleanize extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->config_booleanize = true;
$this->smarty->config_booleanize = true;
return;
}
}

View File

@@ -18,7 +18,8 @@
class Smarty_Method_enableConfigOverwrite extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->config_overwrite = true;
$this->smarty->config_overwrite = true;
return;
}
}

View File

@@ -18,7 +18,8 @@
class Smarty_Method_enableConfigReadHidden extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->config_read_hidden = true;
$this->smarty->config_read_hidden = true;
return;
}
}

View File

@@ -18,7 +18,8 @@
class Smarty_Method_EnableDebugging extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->debugging = true;
$this->smarty->debugging = true;
return;
}
}

View File

@@ -18,7 +18,8 @@
class Smarty_Method_EnableDebuggingUrlCtrl extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->debugging_ctrl = 'URL';
$this->smarty->debugging_ctrl = 'URL';
return;
}
}

View File

@@ -18,7 +18,8 @@
class Smarty_Method_enableDefaultTimezone extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->set_timezone = true;
$this->smarty->set_timezone = true;
return;
}
}

View File

@@ -18,7 +18,8 @@
class Smarty_Method_enableForceCompile extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->force_compile = true;
$this->smarty->force_compile = true;
return;
}
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* Smarty method isCacheModifyCheck
*
* is cache modify check
*
* @package Smarty
* @subpackage SmartyMethod
* @author Uwe Tews
*/
/**
* Smarty class isCacheModifyCheck
*
* is cache modify check
*/
class Smarty_Method_isCacheModifyCheck extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->cache_modified_check;
}
}
?>

View File

@@ -0,0 +1,25 @@
<?php
/**
* Smarty method isCaching
*
* is caching
*
* @package Smarty
* @subpackage SmartyMethod
* @author Uwe Tews
*/
/**
* Smarty class isCaching
*
* is caching
*/
class Smarty_Method_isCaching extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->caching;
}
}
?>

View File

@@ -0,0 +1,25 @@
<?php
/**
* Smarty method isCompileCheck
*
* is compile checking
*
* @package Smarty
* @subpackage SmartyMethod
* @author Uwe Tews
*/
/**
* Smarty class isCompileCheck
*
* is compile checking
*/
class Smarty_Method_isCompileCheck extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->compile_check;
}
}
?>

View File

@@ -0,0 +1,25 @@
<?php
/**
* Smarty method isConfigBooleanize
*
* is config booleanize mode
*
* @package Smarty
* @subpackage SmartyMethod
* @author Uwe Tews
*/
/**
* Smarty class isConfigBooleanize
*
* is config booleanize mode
*/
class Smarty_Method_isConfigBooleanize extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->config_booleanize;
}
}
?>

View File

@@ -0,0 +1,26 @@
<?php
/**
* Smarty method isConfigOverwrite
*
* is config overwrite mode
*
* @package Smarty
* @subpackage SmartyMethod
* @author Uwe Tews
*/
/**
* Smarty class isConfigOverwrite
*
* is config overwrite mode
*/
class Smarty_Method_isConfigOverwrite extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->config_overwrite;
}
}
?>

View File

@@ -0,0 +1,25 @@
<?php
/**
* Smarty method isConfigReadHidden
*
* is config read hidden mode
*
* @package Smarty
* @subpackage SmartyMethod
* @author Uwe Tews
*/
/**
* Smarty class isConfigReadHidden
*
* is config read hidden mode
*/
class Smarty_Method_isConfigReadHidden extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->config_read_hidden;
}
}
?>

View File

@@ -0,0 +1,25 @@
<?php
/**
* Smarty method isDebugging
*
* is debugging
*
* @package Smarty
* @subpackage SmartyMethod
* @author Uwe Tews
*/
/**
* Smarty class isDebugging
*
* is debugging
*/
class Smarty_Method_isDebugging extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->debugging;
}
}
?>

View File

@@ -0,0 +1,25 @@
<?php
/**
* Smarty method isDebuggingUrlCtrl
*
* is possibility to is debugging by SMARTY_DEBUG attribute
*
* @package Smarty
* @subpackage SmartyMethod
* @author Uwe Tews
*/
/**
* Smarty class isDebuggingUrlCtrl
*
* is possibility to is debugging by SMARTY_DEBUG attribute
*/
class Smarty_Method_isDebuggingUrlCtrl extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->debugging_ctrl != 'none';
}
}
?>

View File

@@ -0,0 +1,25 @@
<?php
/**
* Smarty method isDefaultTimezone
*
* is setting of default timezone
*
* @package Smarty
* @subpackage SmartyMethod
* @author Uwe Tews
*/
/**
* Smarty class isDefaultTimezone
*
* is setting of default timezone
*/
class Smarty_Method_isDefaultTimezone extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->set_timezone = false;
}
}
?>

View File

@@ -0,0 +1,25 @@
<?php
/**
* Smarty method isForceCompile
*
* is forced compiling
*
* @package Smarty
* @subpackage SmartyMethod
* @author Uwe Tews
*/
/**
* Smarty class isForceCompile
*
* is forced compiling
*/
class Smarty_Method_isForceCompile extends Smarty_Internal_Base {
public function execute()
{
return $this->smarty->force_compile;
}
}
?>

View File

@@ -26,6 +26,7 @@ class Smarty_Method_SetConfigDir extends Smarty_Internal_Base {
public function execute($config_dir)
{
$this->smarty->config_dir = $config_dir;
return;
}
}

View File

@@ -26,6 +26,7 @@ class Smarty_Method_SetPluginsDir extends Smarty_Internal_Base {
public function execute($plugins_dir)
{
$this->smarty->plugins_dir = (array)$plugins_dir;
return;
}
}