mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 10:54:27 +02:00
support foo->bar[index] syntax
This commit is contained in:
1
NEWS
1
NEWS
@@ -1,3 +1,4 @@
|
|||||||
|
- support $foo->bar[index] syntax (Monte)
|
||||||
- add get_registered_object function (messju, Monte)
|
- add get_registered_object function (messju, Monte)
|
||||||
- treat unrecognized param attribute syntax as string (Monte)
|
- treat unrecognized param attribute syntax as string (Monte)
|
||||||
- support $smarty.const.$foo syntax (messju, Monte)
|
- support $smarty.const.$foo syntax (messju, Monte)
|
||||||
|
@@ -227,7 +227,8 @@ class Smarty
|
|||||||
'IF_FUNCS' => array('array', 'list',
|
'IF_FUNCS' => array('array', 'list',
|
||||||
'isset', 'empty',
|
'isset', 'empty',
|
||||||
'count', 'sizeof',
|
'count', 'sizeof',
|
||||||
'in_array', 'is_array'),
|
'in_array', 'is_array',
|
||||||
|
'true','false'),
|
||||||
'INCLUDE_ANY' => false,
|
'INCLUDE_ANY' => false,
|
||||||
'PHP_TAGS' => false,
|
'PHP_TAGS' => false,
|
||||||
'MODIFIER_FUNCS' => array('count'),
|
'MODIFIER_FUNCS' => array('count'),
|
||||||
|
@@ -139,7 +139,7 @@ class Smarty_Compiler extends Smarty {
|
|||||||
// $foo->bar($foo, "foo")
|
// $foo->bar($foo, "foo")
|
||||||
// $foo->bar->foo()
|
// $foo->bar->foo()
|
||||||
// $foo->bar->foo->bar()
|
// $foo->bar->foo->bar()
|
||||||
$this->_obj_ext_regexp = '\->(?:\w+|\$?' . $this->_dvar_guts_regexp . ')';
|
$this->_obj_ext_regexp = '\->(?:\$?' . $this->_dvar_guts_regexp . ')';
|
||||||
$this->_obj_params_regexp = '\((?:\w+|'
|
$this->_obj_params_regexp = '\((?:\w+|'
|
||||||
. $this->_var_regexp . '(?:\s*,\s*(?:(?:\w+|'
|
. $this->_var_regexp . '(?:\s*,\s*(?:(?:\w+|'
|
||||||
. $this->_var_regexp . ')))*)?\)';
|
. $this->_var_regexp . ')))*)?\)';
|
||||||
@@ -1084,8 +1084,8 @@ class Smarty_Compiler extends Smarty {
|
|||||||
|
|
||||||
/* Tokenize args for 'if' tag. */
|
/* Tokenize args for 'if' tag. */
|
||||||
preg_match_all('/(?>
|
preg_match_all('/(?>
|
||||||
' . $this->_obj_call_regexp . '(?:' . $this->_mod_regexp . '*) | # valid object call
|
' . $this->_obj_call_regexp . '(?:' . $this->_mod_regexp . '*)? | # valid object call
|
||||||
' . $this->_var_regexp . '(?:' . $this->_mod_regexp . '*) | # var or quoted string
|
' . $this->_var_regexp . '(?:' . $this->_mod_regexp . '*)? | # var or quoted string
|
||||||
\-?\d+(?:\.\d+)?|\.\d+|!==|<=>|===|==|!=|<=|>=|\&\&|\|\||\(|\)|,|\!|\^|=|\&|\~|<|>|\||\%|\+|\-|\/|\*|\@ | # valid non-word token
|
\-?\d+(?:\.\d+)?|\.\d+|!==|<=>|===|==|!=|<=|>=|\&\&|\|\||\(|\)|,|\!|\^|=|\&|\~|<|>|\||\%|\+|\-|\/|\*|\@ | # valid non-word token
|
||||||
\b\w+\b | # valid word token
|
\b\w+\b | # valid word token
|
||||||
\S+ # anything else
|
\S+ # anything else
|
||||||
@@ -1212,11 +1212,8 @@ class Smarty_Compiler extends Smarty {
|
|||||||
!in_array($token, $this->security_settings['IF_FUNCS'])) {
|
!in_array($token, $this->security_settings['IF_FUNCS'])) {
|
||||||
$this->_syntax_error("(secure mode) '$token' not allowed in if statement", E_USER_ERROR, __FILE__, __LINE__);
|
$this->_syntax_error("(secure mode) '$token' not allowed in if statement", E_USER_ERROR, __FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
} elseif(preg_match('!^' . $this->_var_regexp . '(?:' . $this->_mod_regexp . '*)$!', $token)) {
|
} elseif(preg_match('!^' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '(?:' . $this->_mod_regexp . '*)$!', $token)) {
|
||||||
// variable
|
// object or variable
|
||||||
$token = $this->_parse_var_props($token);
|
|
||||||
} elseif(preg_match('!^' . $this->_obj_call_regexp . '(?:' . $this->_mod_regexp . '*)$!', $token)) {
|
|
||||||
// object
|
|
||||||
$token = $this->_parse_var_props($token);
|
$token = $this->_parse_var_props($token);
|
||||||
} elseif(is_numeric($token)) {
|
} elseif(is_numeric($token)) {
|
||||||
// number, skip it
|
// number, skip it
|
||||||
@@ -1474,8 +1471,8 @@ class Smarty_Compiler extends Smarty {
|
|||||||
$modifiers = empty($modifiers) ? $_default_mod_string : $_default_mod_string . '|' . $modifiers;
|
$modifiers = empty($modifiers) ? $_default_mod_string : $_default_mod_string . '|' . $modifiers;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get [foo] and .foo and ->foo() pieces
|
// get [foo] and .foo and ->foo and (...) pieces
|
||||||
preg_match_all('!(?:^\w+)|(?:' . $this->_obj_ext_regexp . ')+(?:' . $this->_obj_params_regexp . ')?|(?:' . $this->_var_bracket_regexp . ')|\.\$?\w+!', $var_ref, $match);
|
preg_match_all('!(?:^\w+)|' . $this->_obj_params_regexp . '|(?:' . $this->_var_bracket_regexp . ')|->\w+|\.\$?\w+|\S+!', $var_ref, $match);
|
||||||
|
|
||||||
$indexes = $match[0];
|
$indexes = $match[0];
|
||||||
$var_name = array_shift($indexes);
|
$var_name = array_shift($indexes);
|
||||||
@@ -1520,23 +1517,11 @@ class Smarty_Compiler extends Smarty {
|
|||||||
$this->_syntax_error('call to internal object members is not allowed', E_USER_ERROR, __FILE__, __LINE__);
|
$this->_syntax_error('call to internal object members is not allowed', E_USER_ERROR, __FILE__, __LINE__);
|
||||||
} elseif($this->security && substr($index,2,1) == '_') {
|
} elseif($this->security && substr($index,2,1) == '_') {
|
||||||
$this->_syntax_error('(secure) call to private object member is not allowed', E_USER_ERROR, __FILE__, __LINE__);
|
$this->_syntax_error('(secure) call to private object member is not allowed', E_USER_ERROR, __FILE__, __LINE__);
|
||||||
} else {
|
|
||||||
if(preg_match('!((?:' . $this->_obj_ext_regexp . ')+)(' . $this->_obj_params_regexp . ')?!', $index, $match)) {
|
|
||||||
if(!empty($match[2])) {
|
|
||||||
// parse object parameters
|
|
||||||
$index = str_replace($match[2], $this->_parse_parenth_args($match[2]), $index);
|
|
||||||
}
|
|
||||||
if(preg_match_all('!' . $this->_dvar_regexp . '!', $match[1], $_dvar_match)) {
|
|
||||||
// parse embedded variables
|
|
||||||
$_match_replace = $match[1];
|
|
||||||
foreach($_dvar_match[0] as $_curr_var) {
|
|
||||||
$_match_replace = str_replace($_curr_var, '{' . $this->_parse_var($_curr_var) . '}', $_match_replace);
|
|
||||||
}
|
|
||||||
$index = str_replace($match[1], $_match_replace, $index);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$output .= $index;
|
$output .= $index;
|
||||||
}
|
} elseif ($index{0} == '(') {
|
||||||
|
$index = $this->_parse_parenth_args($index);
|
||||||
|
$output .= $index;
|
||||||
} else {
|
} else {
|
||||||
$output .= $index;
|
$output .= $index;
|
||||||
}
|
}
|
||||||
|
@@ -227,7 +227,8 @@ class Smarty
|
|||||||
'IF_FUNCS' => array('array', 'list',
|
'IF_FUNCS' => array('array', 'list',
|
||||||
'isset', 'empty',
|
'isset', 'empty',
|
||||||
'count', 'sizeof',
|
'count', 'sizeof',
|
||||||
'in_array', 'is_array'),
|
'in_array', 'is_array',
|
||||||
|
'true','false'),
|
||||||
'INCLUDE_ANY' => false,
|
'INCLUDE_ANY' => false,
|
||||||
'PHP_TAGS' => false,
|
'PHP_TAGS' => false,
|
||||||
'MODIFIER_FUNCS' => array('count'),
|
'MODIFIER_FUNCS' => array('count'),
|
||||||
|
@@ -139,7 +139,7 @@ class Smarty_Compiler extends Smarty {
|
|||||||
// $foo->bar($foo, "foo")
|
// $foo->bar($foo, "foo")
|
||||||
// $foo->bar->foo()
|
// $foo->bar->foo()
|
||||||
// $foo->bar->foo->bar()
|
// $foo->bar->foo->bar()
|
||||||
$this->_obj_ext_regexp = '\->(?:\w+|\$?' . $this->_dvar_guts_regexp . ')';
|
$this->_obj_ext_regexp = '\->(?:\$?' . $this->_dvar_guts_regexp . ')';
|
||||||
$this->_obj_params_regexp = '\((?:\w+|'
|
$this->_obj_params_regexp = '\((?:\w+|'
|
||||||
. $this->_var_regexp . '(?:\s*,\s*(?:(?:\w+|'
|
. $this->_var_regexp . '(?:\s*,\s*(?:(?:\w+|'
|
||||||
. $this->_var_regexp . ')))*)?\)';
|
. $this->_var_regexp . ')))*)?\)';
|
||||||
@@ -1084,8 +1084,8 @@ class Smarty_Compiler extends Smarty {
|
|||||||
|
|
||||||
/* Tokenize args for 'if' tag. */
|
/* Tokenize args for 'if' tag. */
|
||||||
preg_match_all('/(?>
|
preg_match_all('/(?>
|
||||||
' . $this->_obj_call_regexp . '(?:' . $this->_mod_regexp . '*) | # valid object call
|
' . $this->_obj_call_regexp . '(?:' . $this->_mod_regexp . '*)? | # valid object call
|
||||||
' . $this->_var_regexp . '(?:' . $this->_mod_regexp . '*) | # var or quoted string
|
' . $this->_var_regexp . '(?:' . $this->_mod_regexp . '*)? | # var or quoted string
|
||||||
\-?\d+(?:\.\d+)?|\.\d+|!==|<=>|===|==|!=|<=|>=|\&\&|\|\||\(|\)|,|\!|\^|=|\&|\~|<|>|\||\%|\+|\-|\/|\*|\@ | # valid non-word token
|
\-?\d+(?:\.\d+)?|\.\d+|!==|<=>|===|==|!=|<=|>=|\&\&|\|\||\(|\)|,|\!|\^|=|\&|\~|<|>|\||\%|\+|\-|\/|\*|\@ | # valid non-word token
|
||||||
\b\w+\b | # valid word token
|
\b\w+\b | # valid word token
|
||||||
\S+ # anything else
|
\S+ # anything else
|
||||||
@@ -1212,11 +1212,8 @@ class Smarty_Compiler extends Smarty {
|
|||||||
!in_array($token, $this->security_settings['IF_FUNCS'])) {
|
!in_array($token, $this->security_settings['IF_FUNCS'])) {
|
||||||
$this->_syntax_error("(secure mode) '$token' not allowed in if statement", E_USER_ERROR, __FILE__, __LINE__);
|
$this->_syntax_error("(secure mode) '$token' not allowed in if statement", E_USER_ERROR, __FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
} elseif(preg_match('!^' . $this->_var_regexp . '(?:' . $this->_mod_regexp . '*)$!', $token)) {
|
} elseif(preg_match('!^' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '(?:' . $this->_mod_regexp . '*)$!', $token)) {
|
||||||
// variable
|
// object or variable
|
||||||
$token = $this->_parse_var_props($token);
|
|
||||||
} elseif(preg_match('!^' . $this->_obj_call_regexp . '(?:' . $this->_mod_regexp . '*)$!', $token)) {
|
|
||||||
// object
|
|
||||||
$token = $this->_parse_var_props($token);
|
$token = $this->_parse_var_props($token);
|
||||||
} elseif(is_numeric($token)) {
|
} elseif(is_numeric($token)) {
|
||||||
// number, skip it
|
// number, skip it
|
||||||
@@ -1474,8 +1471,8 @@ class Smarty_Compiler extends Smarty {
|
|||||||
$modifiers = empty($modifiers) ? $_default_mod_string : $_default_mod_string . '|' . $modifiers;
|
$modifiers = empty($modifiers) ? $_default_mod_string : $_default_mod_string . '|' . $modifiers;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get [foo] and .foo and ->foo() pieces
|
// get [foo] and .foo and ->foo and (...) pieces
|
||||||
preg_match_all('!(?:^\w+)|(?:' . $this->_obj_ext_regexp . ')+(?:' . $this->_obj_params_regexp . ')?|(?:' . $this->_var_bracket_regexp . ')|\.\$?\w+!', $var_ref, $match);
|
preg_match_all('!(?:^\w+)|' . $this->_obj_params_regexp . '|(?:' . $this->_var_bracket_regexp . ')|->\w+|\.\$?\w+|\S+!', $var_ref, $match);
|
||||||
|
|
||||||
$indexes = $match[0];
|
$indexes = $match[0];
|
||||||
$var_name = array_shift($indexes);
|
$var_name = array_shift($indexes);
|
||||||
@@ -1520,23 +1517,11 @@ class Smarty_Compiler extends Smarty {
|
|||||||
$this->_syntax_error('call to internal object members is not allowed', E_USER_ERROR, __FILE__, __LINE__);
|
$this->_syntax_error('call to internal object members is not allowed', E_USER_ERROR, __FILE__, __LINE__);
|
||||||
} elseif($this->security && substr($index,2,1) == '_') {
|
} elseif($this->security && substr($index,2,1) == '_') {
|
||||||
$this->_syntax_error('(secure) call to private object member is not allowed', E_USER_ERROR, __FILE__, __LINE__);
|
$this->_syntax_error('(secure) call to private object member is not allowed', E_USER_ERROR, __FILE__, __LINE__);
|
||||||
} else {
|
|
||||||
if(preg_match('!((?:' . $this->_obj_ext_regexp . ')+)(' . $this->_obj_params_regexp . ')?!', $index, $match)) {
|
|
||||||
if(!empty($match[2])) {
|
|
||||||
// parse object parameters
|
|
||||||
$index = str_replace($match[2], $this->_parse_parenth_args($match[2]), $index);
|
|
||||||
}
|
|
||||||
if(preg_match_all('!' . $this->_dvar_regexp . '!', $match[1], $_dvar_match)) {
|
|
||||||
// parse embedded variables
|
|
||||||
$_match_replace = $match[1];
|
|
||||||
foreach($_dvar_match[0] as $_curr_var) {
|
|
||||||
$_match_replace = str_replace($_curr_var, '{' . $this->_parse_var($_curr_var) . '}', $_match_replace);
|
|
||||||
}
|
|
||||||
$index = str_replace($match[1], $_match_replace, $index);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$output .= $index;
|
$output .= $index;
|
||||||
}
|
} elseif ($index{0} == '(') {
|
||||||
|
$index = $this->_parse_parenth_args($index);
|
||||||
|
$output .= $index;
|
||||||
} else {
|
} else {
|
||||||
$output .= $index;
|
$output .= $index;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user