mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-07 11:54:26 +02:00
Updated to allow method chaining for PHP4 and PHP5 (U.Tews)
This commit is contained in:
@@ -74,12 +74,17 @@ class Smarty_Compiler extends Smarty {
|
|||||||
var $_strip_depth = 0;
|
var $_strip_depth = 0;
|
||||||
var $_additional_newline = "\n";
|
var $_additional_newline = "\n";
|
||||||
|
|
||||||
|
var $PHP5 = false;
|
||||||
|
|
||||||
|
|
||||||
/**#@-*/
|
/**#@-*/
|
||||||
/**
|
/**
|
||||||
* The class constructor.
|
* The class constructor.
|
||||||
*/
|
*/
|
||||||
function Smarty_Compiler()
|
function Smarty_Compiler()
|
||||||
{
|
{
|
||||||
|
if (substr(phpversion(),0,1) == '5') $this->PHP5 = true;
|
||||||
|
|
||||||
// matches double quoted strings:
|
// matches double quoted strings:
|
||||||
// "foobar"
|
// "foobar"
|
||||||
// "foo\"bar"
|
// "foo\"bar"
|
||||||
@@ -152,16 +157,20 @@ class Smarty_Compiler extends Smarty {
|
|||||||
// $foo->bar($foo->bar)
|
// $foo->bar($foo->bar)
|
||||||
// $foo->bar($foo->bar())
|
// $foo->bar($foo->bar())
|
||||||
// $foo->bar($foo->bar($blah,$foo,44,"foo",$foo[0].bar))
|
// $foo->bar($foo->bar($blah,$foo,44,"foo",$foo[0].bar))
|
||||||
|
// $foo->getBar()->getFoo()
|
||||||
|
// $foo->getBar()->foo
|
||||||
$this->_obj_ext_regexp = '\->(?:\$?' . $this->_dvar_guts_regexp . ')';
|
$this->_obj_ext_regexp = '\->(?:\$?' . $this->_dvar_guts_regexp . ')';
|
||||||
$this->_obj_restricted_param_regexp = '(?:'
|
$this->_obj_restricted_param_regexp = '(?:'
|
||||||
. '(?:' . $this->_var_regexp . '|' . $this->_num_const_regexp . ')(?:' . $this->_obj_ext_regexp . '(?:\((?:(?:' . $this->_var_regexp . '|' . $this->_num_const_regexp . ')'
|
. '(?:' . $this->_var_regexp . '|' . $this->_num_const_regexp . ')(?:' . $this->_obj_ext_regexp . '(?:\((?:(?:' . $this->_var_regexp . '|' . $this->_num_const_regexp . ')'
|
||||||
. '(?:\s*,\s*(?:' . $this->_var_regexp . '|' . $this->_num_const_regexp . '))*)?\))?)*)';
|
. '(?:\s*,\s*(?:' . $this->_var_regexp . '|' . $this->_num_const_regexp . '))*)?\))?)*)';
|
||||||
|
|
||||||
$this->_obj_single_param_regexp = '(?:\w+|' . $this->_obj_restricted_param_regexp . '(?:\s*,\s*(?:(?:\w+|'
|
$this->_obj_single_param_regexp = '(?:\w+|' . $this->_obj_restricted_param_regexp . '(?:\s*,\s*(?:(?:\w+|'
|
||||||
. $this->_var_regexp . $this->_obj_restricted_param_regexp . ')))*)';
|
. $this->_var_regexp . $this->_obj_restricted_param_regexp . ')))*)';
|
||||||
|
|
||||||
$this->_obj_params_regexp = '\((?:' . $this->_obj_single_param_regexp
|
$this->_obj_params_regexp = '\((?:' . $this->_obj_single_param_regexp
|
||||||
. '(?:\s*,\s*' . $this->_obj_single_param_regexp . ')*)?\)';
|
. '(?:\s*,\s*' . $this->_obj_single_param_regexp . ')*)?\)';
|
||||||
$this->_obj_start_regexp = '(?:' . $this->_dvar_regexp . '(?:' . $this->_obj_ext_regexp . ')+)';
|
$this->_obj_start_regexp = '(?:' . $this->_dvar_regexp . '(?:' . $this->_obj_ext_regexp . ')+)';
|
||||||
$this->_obj_call_regexp = '(?:' . $this->_obj_start_regexp . '(?:' . $this->_obj_params_regexp . ')?(?:' . $this->_dvar_math_regexp . '(?:' . $this->_num_const_regexp . '|' . $this->_dvar_math_var_regexp . ')*)?)';
|
$this->_obj_call_regexp = '(?:' . $this->_obj_start_regexp . '(?:' . $this->_obj_params_regexp . '(?:' . $this->_obj_ext_regexp . '(?:'.$this->_obj_params_regexp . ')?)*' . ')?(?:' . $this->_dvar_math_regexp . '(?:' . $this->_num_const_regexp . '|' . $this->_dvar_math_var_regexp . ')*)?)';
|
||||||
|
|
||||||
// matches valid modifier syntax:
|
// matches valid modifier syntax:
|
||||||
// |foo
|
// |foo
|
||||||
@@ -1821,6 +1830,10 @@ class Smarty_Compiler extends Smarty {
|
|||||||
$_output .= '->{(($_var=$this->_tpl_vars[\''.substr($_index,3).'\']) && substr($_var,0,2)!=\'__\') ? $_var : $this->trigger_error("cannot access property \\"$_var\\"")}';
|
$_output .= '->{(($_var=$this->_tpl_vars[\''.substr($_index,3).'\']) && substr($_var,0,2)!=\'__\') ? $_var : $this->trigger_error("cannot access property \\"$_var\\"")}';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (!$this->PHP5) {
|
||||||
|
$_PHP4_method_chain = true;
|
||||||
|
$_output .= "; \$_foo = \$_foo";
|
||||||
|
}
|
||||||
$_output .= $_index;
|
$_output .= $_index;
|
||||||
}
|
}
|
||||||
} elseif (substr($_index, 0, 1) == '(') {
|
} elseif (substr($_index, 0, 1) == '(') {
|
||||||
@@ -1832,8 +1845,13 @@ class Smarty_Compiler extends Smarty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($_PHP4_method_chain) {
|
||||||
|
$_tmp = str_replace("'","\'",'$_foo = '.$_output.'; return $_foo;');
|
||||||
|
return "eval('".$_tmp."')";
|
||||||
|
} else {
|
||||||
return $_output;
|
return $_output;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parse arguments in function call parenthesis
|
* parse arguments in function call parenthesis
|
||||||
|
Reference in New Issue
Block a user