- added __toString method to the Smarty_Variable class

This commit is contained in:
Uwe.Tews
2010-06-18 15:10:35 +00:00
parent 6ba7d10ccd
commit 7cd84ed640
2 changed files with 147 additions and 133 deletions

View File

@@ -1,6 +1,15 @@
18/06/2010
- added __toString method to the Smarty_Variable class
14/06/2010 14/06/2010
- make handling of Smarty comments followed by newline BC to Smarty2 - make handling of Smarty comments followed by newline BC to Smarty2
===== RC2 =====
13/06/2010 13/06/2010
- bugfix Smarty3 did not handle hexadecimals like 0x0F as numerical value - bugfix Smarty3 did not handle hexadecimals like 0x0F as numerical value
- bugifx Smarty3 did not accept numerical constants like .1 or 2. (without a leading or trailing digit) - bugifx Smarty3 did not accept numerical constants like .1 or 2. (without a leading or trailing digit)

View File

@@ -1,30 +1,30 @@
<?php <?php
/** /**
* Smarty Internal Plugin Data * Smarty Internal Plugin Data
* *
* This file contains the basic classes and methodes for template and variable creation * This file contains the basic classes and methodes for template and variable creation
* *
* @package Smarty * @package Smarty
* @subpackage Templates * @subpackage Templates
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Base class with template and variable methodes * Base class with template and variable methodes
*/ */
class Smarty_Internal_Data { class Smarty_Internal_Data {
// class used for templates // class used for templates
public $template_class = 'Smarty_Internal_Template'; public $template_class = 'Smarty_Internal_Template';
/** /**
* assigns a Smarty variable * assigns a Smarty variable
* *
* @param array $ |string $tpl_var the template variable name(s) * @param array $ |string $tpl_var the template variable name(s)
* @param mixed $value the value to assign * @param mixed $value the value to assign
* @param boolean $nocache if true any output of this variable will be not cached * @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) * @param boolean $scope the scope the variable will have (local,parent or root)
*/ */
public function assign($tpl_var, $value = null, $nocache = false, $scope = SMARTY_LOCAL_SCOPE) public function assign($tpl_var, $value = null, $nocache = false, $scope = SMARTY_LOCAL_SCOPE)
{ {
if (is_array($tpl_var)) { if (is_array($tpl_var)) {
@@ -40,12 +40,12 @@ class Smarty_Internal_Data {
} }
} }
/** /**
* assigns a global Smarty variable * assigns a global Smarty variable
* *
* @param string $varname the global variable name * @param string $varname the global variable name
* @param mixed $value the value to assign * @param mixed $value the value to assign
* @param boolean $nocache if true any output of this variable will be not cached * @param boolean $nocache if true any output of this variable will be not cached
*/ */
public function assignGlobal($varname, $value = null, $nocache = false) public function assignGlobal($varname, $value = null, $nocache = false)
{ {
if ($varname != '') { if ($varname != '') {
@@ -53,13 +53,13 @@ class Smarty_Internal_Data {
} }
} }
/** /**
* assigns values to template variables by reference * assigns values to template variables by reference
* *
* @param string $tpl_var the template variable name * @param string $tpl_var the template variable name
* @param mixed $ &$value the referenced value to assign * @param mixed $ &$value the referenced value to assign
* @param boolean $nocache if true any output of this variable will be not cached * @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) * @param boolean $scope the scope the variable will have (local,parent or root)
*/ */
public function assignByRef($tpl_var, &$value, $nocache = false, $scope = SMARTY_LOCAL_SCOPE) public function assignByRef($tpl_var, &$value, $nocache = false, $scope = SMARTY_LOCAL_SCOPE)
{ {
if ($tpl_var != '') { if ($tpl_var != '') {
@@ -68,27 +68,27 @@ class Smarty_Internal_Data {
} }
} }
/** /**
* wrapper function for Smarty 2 BC * wrapper function for Smarty 2 BC
* *
* @param string $tpl_var the template variable name * @param string $tpl_var the template variable name
* @param mixed $ &$value the referenced value to assign * @param mixed $ &$value the referenced value to assign
* @param boolean $nocache if true any output of this variable will be not cached * @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) * @param boolean $scope the scope the variable will have (local,parent or root)
*/ */
public function assign_by_ref($tpl_var, &$value, $nocache = false, $scope = SMARTY_LOCAL_SCOPE) public function assign_by_ref($tpl_var, &$value, $nocache = false, $scope = SMARTY_LOCAL_SCOPE)
{ {
trigger_error("function call 'assign_by_ref' is unknown or deprecated, use 'assignByRef'",E_USER_NOTICE); trigger_error("function call 'assign_by_ref' is unknown or deprecated, use 'assignByRef'", E_USER_NOTICE);
$this->assignByRef($tpl_var,$value,$nocache,$scope); $this->assignByRef($tpl_var, $value, $nocache, $scope);
} }
/** /**
* appends values to template variables * appends values to template variables
* *
* @param array $ |string $tpl_var the template variable name(s) * @param array $ |string $tpl_var the template variable name(s)
* @param mixed $value the value to append * @param mixed $value the value to append
* @param boolean $merge flag if array elements shall be merged * @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 $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) * @param boolean $scope the scope the variable will have (local,parent or root)
*/ */
public function append($tpl_var, $value = null, $merge = false, $nocache = false, $scope = SMARTY_LOCAL_SCOPE) public function append($tpl_var, $value = null, $merge = false, $nocache = false, $scope = SMARTY_LOCAL_SCOPE)
{ {
if (is_array($tpl_var)) { if (is_array($tpl_var)) {
@@ -146,12 +146,12 @@ class Smarty_Internal_Data {
} }
/** /**
* appends values to template variables by reference * appends values to template variables by reference
* *
* @param string $tpl_var the template variable name * @param string $tpl_var the template variable name
* @param mixed $ &$value the referenced value to append * @param mixed $ &$value the referenced value to append
* @param boolean $merge flag if array elements shall be merged * @param boolean $merge flag if array elements shall be merged
*/ */
public function appendByRef($tpl_var, &$value, $merge = false) public function appendByRef($tpl_var, &$value, $merge = false)
{ {
if ($tpl_var != '' && isset($value)) { if ($tpl_var != '' && isset($value)) {
@@ -171,23 +171,23 @@ class Smarty_Internal_Data {
} }
} }
/** /**
* wrapper function for Smarty 2 BC * wrapper function for Smarty 2 BC
* *
* @param string $tpl_var the template variable name * @param string $tpl_var the template variable name
* @param mixed $ &$value the referenced value to append * @param mixed $ &$value the referenced value to append
* @param boolean $merge flag if array elements shall be merged * @param boolean $merge flag if array elements shall be merged
*/ */
public function append_by_ref($tpl_var, &$value, $merge = false) public function append_by_ref($tpl_var, &$value, $merge = false)
{ {
trigger_error("function call 'append_by_ref' is unknown or deprecated, use 'appendByRef'",E_USER_NOTICE); trigger_error("function call 'append_by_ref' is unknown or deprecated, use 'appendByRef'", E_USER_NOTICE);
$this->appendByRef($tpl_var,$value,$merge); $this->appendByRef($tpl_var, $value, $merge);
} }
/** /**
* Returns a single or all template variables * Returns a single or all template variables
* *
* @param string $varname variable name or null * @param string $varname variable name or null
* @return string variable value or or array of variables * @return string variable value or or array of variables
*/ */
function getTemplateVars($varname = null, $_ptr = null, $search_parents = true) function getTemplateVars($varname = null, $_ptr = null, $search_parents = true)
{ {
if (isset($varname)) { if (isset($varname)) {
@@ -219,13 +219,13 @@ class Smarty_Internal_Data {
} }
return $_result; return $_result;
} }
} }
/** /**
* clear the given assigned template variable. * clear the given assigned template variable.
* *
* @param string $ |array $tpl_var the template variable(s) to clear * @param string $ |array $tpl_var the template variable(s) to clear
*/ */
public function clearAssign($tpl_var) public function clearAssign($tpl_var)
{ {
if (is_array($tpl_var)) { if (is_array($tpl_var)) {
@@ -238,19 +238,19 @@ class Smarty_Internal_Data {
} }
/** /**
* clear all the assigned template variables. * clear all the assigned template variables.
*/ */
public function clearAllAssign() public function clearAllAssign()
{ {
$this->tpl_vars = array(); $this->tpl_vars = array();
} }
/** /**
* load a config file, optionally load just selected sections * load a config file, optionally load just selected sections
* *
* @param string $config_file filename * @param string $config_file filename
* @param mixed $sections array of section names, single section or null * @param mixed $sections array of section names, single section or null
*/ */
public function configLoad($config_file, $sections = null) public function configLoad($config_file, $sections = null)
{ {
// load Config class // load Config class
@@ -259,13 +259,13 @@ class Smarty_Internal_Data {
} }
/** /**
* gets the object of a Smarty variable * gets the object of a Smarty variable
* *
* @param string $variable the name of the Smarty variable * @param string $variable the name of the Smarty variable
* @param object $_ptr optional pointer to data object * @param object $_ptr optional pointer to data object
* @param boolean $search_parents search also in parent data * @param boolean $search_parents search also in parent data
* @return object the object of the variable * @return object the object of the variable
*/ */
public function getVariable($variable, $_ptr = null, $search_parents = true, $error_enable = true) public function getVariable($variable, $_ptr = null, $search_parents = true, $error_enable = true)
{ {
if ($_ptr === null) { if ($_ptr === null) {
@@ -293,11 +293,11 @@ class Smarty_Internal_Data {
} }
} }
/** /**
* gets a config variable * gets a config variable
* *
* @param string $variable the name of the config variable * @param string $variable the name of the config variable
* @return mixed the value of the config variable * @return mixed the value of the config variable
*/ */
public function getConfigVariable($variable) public function getConfigVariable($variable)
{ {
$_ptr = $this; $_ptr = $this;
@@ -316,11 +316,11 @@ class Smarty_Internal_Data {
} }
} }
/** /**
* gets a stream variable * gets a stream variable
* *
* @param string $variable the stream of the variable * @param string $variable the stream of the variable
* @return mixed the value of the stream variable * @return mixed the value of the stream variable
*/ */
public function getStreamVariable($variable) public function getStreamVariable($variable)
{ {
$_result = ''; $_result = '';
@@ -340,11 +340,11 @@ class Smarty_Internal_Data {
} }
/** /**
* Returns a single or all config variables * Returns a single or all config variables
* *
* @param string $varname variable name or null * @param string $varname variable name or null
* @return string variable value or or array of variables * @return string variable value or or array of variables
*/ */
function getConfigVars($varname = null) function getConfigVars($varname = null)
{ {
if (isset($varname)) { if (isset($varname)) {
@@ -359,10 +359,10 @@ class Smarty_Internal_Data {
} }
/** /**
* Deassigns a single or all config variables * Deassigns a single or all config variables
* *
* @param string $varname variable name or null * @param string $varname variable name or null
*/ */
function clearConfig($varname = null) function clearConfig($varname = null)
{ {
if (isset($varname)) { if (isset($varname)) {
@@ -375,10 +375,10 @@ class Smarty_Internal_Data {
} }
/** /**
* return current time * return current time
* *
* @returns double current time * @returns double current time
*/ */
function _get_time() function _get_time()
{ {
$_mtime = microtime(); $_mtime = microtime();
@@ -388,12 +388,12 @@ class Smarty_Internal_Data {
} }
/** /**
* class for the Smarty data object * class for the Smarty data object
* *
* The Smarty data object will hold Smarty variables in the current scope * The Smarty data object will hold Smarty variables in the current scope
* *
* @param object $parent tpl_vars next higher level of Smarty variables * @param object $parent tpl_vars next higher level of Smarty variables
*/ */
class Smarty_Data extends Smarty_Internal_Data { class Smarty_Data extends Smarty_Internal_Data {
// array of variable objects // array of variable objects
public $tpl_vars = array(); public $tpl_vars = array();
@@ -404,8 +404,8 @@ class Smarty_Data extends Smarty_Internal_Data {
// Smarty object // Smarty object
public $smarty = null; public $smarty = null;
/** /**
* create Smarty data object * create Smarty data object
*/ */
public function __construct ($_parent = null, $smarty = null) public function __construct ($_parent = null, $smarty = null)
{ {
$this->smarty = $smarty; $this->smarty = $smarty;
@@ -423,35 +423,40 @@ class Smarty_Data extends Smarty_Internal_Data {
} }
} }
/** /**
* class for the Smarty variable object * class for the Smarty variable object
* *
* This class defines the Smarty variable object * This class defines the Smarty variable object
*/ */
class Smarty_Variable { class Smarty_Variable {
// template variable // template variable
public $value; public $value;
public $nocache; public $nocache;
public $scope; public $scope;
/** /**
* create Smarty variable object * create Smarty variable object
* *
* @param mixed $value the value to assign * @param mixed $value the value to assign
* @param boolean $nocache if true any output of this variable will be not cached * @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) * @param boolean $scope the scope the variable will have (local,parent or root)
*/ */
public function __construct ($value = null, $nocache = false, $scope = SMARTY_LOCAL_SCOPE) public function __construct ($value = null, $nocache = false, $scope = SMARTY_LOCAL_SCOPE)
{ {
$this->value = $value; $this->value = $value;
$this->nocache = $nocache; $this->nocache = $nocache;
$this->scope = $scope; $this->scope = $scope;
} }
public function __toString ()
{
return $this->value;
}
} }
/** /**
* class for undefined variable object * class for undefined variable object
* *
* This class defines an object for undefined variable handling * This class defines an object for undefined variable handling
*/ */
class Undefined_Smarty_Variable { class Undefined_Smarty_Variable {
// return always false // return always false
public function __get ($name) public function __get ($name)
@@ -464,4 +469,4 @@ class Undefined_Smarty_Variable {
} }
} }
?> ?>