- added chaining to Smarty_Internal_Data so $smarty->assign('a',1)->assign('b',2); is possible now

This commit is contained in:
rodneyrehm
2011-09-27 12:36:50 +00:00
parent b6e6b67548
commit 0cd9821dcc
3 changed files with 32 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
===== trunk ===== ===== trunk =====
27.09.2011 27.09.2011
- bugfix possible warning "attempt to modify property of non-object" in {section} (issue #34) - bugfix possible warning "attempt to modify property of non-object" in {section} (issue #34)
- added chaining to Smarty_Internal_Data so $smarty->assign('a',1)->assign('b',2); is possible now
26.09.2011 26.09.2011
- bugfix repeated calls to same subtemplate did not make use of cached template object - bugfix repeated calls to same subtemplate did not make use of cached template object

View File

@@ -78,7 +78,7 @@ function smarty_block_textformat($params, $content, $template, &$repeat)
$_paragraphs = preg_split('![\r\n]{2}!', $content); $_paragraphs = preg_split('![\r\n]{2}!', $content);
$_output = ''; $_output = '';
for($_x = 0, $_y = count($_paragraphs); $_x < $_y; $_x++) { for ($_x = 0, $_y = count($_paragraphs); $_x < $_y; $_x++) {
if ($_paragraphs[$_x] == '') { if ($_paragraphs[$_x] == '') {
continue; continue;
} }
@@ -101,8 +101,12 @@ function smarty_block_textformat($params, $content, $template, &$repeat)
} }
} }
$_output = implode($wrap_char . $wrap_char, $_paragraphs); $_output = implode($wrap_char . $wrap_char, $_paragraphs);
return $assign ? $template->assign($assign, $_output) : $_output; if ($assign) {
$template->assign($assign, $_output);
} else {
return $_output;
}
} }
?> ?>

View File

@@ -49,6 +49,7 @@ class Smarty_Internal_Data {
* @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)
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/ */
public function assign($tpl_var, $value = null, $nocache = false) public function assign($tpl_var, $value = null, $nocache = false)
{ {
@@ -73,6 +74,8 @@ class Smarty_Internal_Data {
} }
} }
} }
return $this;
} }
/** /**
@@ -81,12 +84,15 @@ class Smarty_Internal_Data {
* @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
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/ */
public function assignGlobal($varname, $value = null, $nocache = false) public function assignGlobal($varname, $value = null, $nocache = false)
{ {
if ($varname != '') { if ($varname != '') {
Smarty::$global_tpl_vars[$varname] = new Smarty_variable($value, $nocache); Smarty::$global_tpl_vars[$varname] = new Smarty_variable($value, $nocache);
} }
return $this;
} }
/** /**
* assigns values to template variables by reference * assigns values to template variables by reference
@@ -94,6 +100,7 @@ class Smarty_Internal_Data {
* @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
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/ */
public function assignByRef($tpl_var, &$value, $nocache = false) public function assignByRef($tpl_var, &$value, $nocache = false)
{ {
@@ -101,6 +108,8 @@ class Smarty_Internal_Data {
$this->tpl_vars[$tpl_var] = new Smarty_variable(null, $nocache); $this->tpl_vars[$tpl_var] = new Smarty_variable(null, $nocache);
$this->tpl_vars[$tpl_var]->value = &$value; $this->tpl_vars[$tpl_var]->value = &$value;
} }
return $this;
} }
/** /**
@@ -110,6 +119,7 @@ class Smarty_Internal_Data {
* @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
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/ */
public function append($tpl_var, $value = null, $merge = false, $nocache = false) public function append($tpl_var, $value = null, $merge = false, $nocache = false)
{ {
@@ -159,6 +169,8 @@ class Smarty_Internal_Data {
} }
} }
} }
return $this;
} }
/** /**
@@ -167,6 +179,7 @@ class Smarty_Internal_Data {
* @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
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/ */
public function appendByRef($tpl_var, &$value, $merge = false) public function appendByRef($tpl_var, &$value, $merge = false)
{ {
@@ -185,6 +198,8 @@ class Smarty_Internal_Data {
$this->tpl_vars[$tpl_var]->value[] = &$value; $this->tpl_vars[$tpl_var]->value[] = &$value;
} }
} }
return $this;
} }
/** /**
@@ -236,6 +251,7 @@ class Smarty_Internal_Data {
* 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
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/ */
public function clearAssign($tpl_var) public function clearAssign($tpl_var)
{ {
@@ -246,14 +262,18 @@ class Smarty_Internal_Data {
} else { } else {
unset($this->tpl_vars[$tpl_var]); unset($this->tpl_vars[$tpl_var]);
} }
return $this;
} }
/** /**
* clear all the assigned template variables. * clear all the assigned template variables.
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/ */
public function clearAllAssign() public function clearAllAssign()
{ {
$this->tpl_vars = array(); $this->tpl_vars = array();
return $this;
} }
/** /**
@@ -261,12 +281,14 @@ class Smarty_Internal_Data {
* *
* @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
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/ */
public function configLoad($config_file, $sections = null) public function configLoad($config_file, $sections = null)
{ {
// load Config class // load Config class
$config = new Smarty_Internal_Config($config_file, $this->smarty, $this); $config = new Smarty_Internal_Config($config_file, $this->smarty, $this);
$config->loadConfigVars($sections); $config->loadConfigVars($sections);
return $this;
} }
/** /**
@@ -389,6 +411,7 @@ 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
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/ */
public function clearConfig($varname = null) public function clearConfig($varname = null)
{ {
@@ -397,6 +420,7 @@ class Smarty_Internal_Data {
} else { } else {
$this->config_vars = array(); $this->config_vars = array();
} }
return $this;
} }
} }