add support for $foo->$bar syntax

This commit is contained in:
mohrt
2003-02-10 20:59:08 +00:00
parent 2a5d061dcd
commit 2bce12e9e0
3 changed files with 31 additions and 12 deletions

1
NEWS
View File

@@ -1,3 +1,4 @@
- support embedded variables in objects (Monte)
- fix bug with objects with no properties (M Mohr, Monte) - fix bug with objects with no properties (M Mohr, Monte)
- support full dollar var syntax in quoted text (Monte) - support full dollar var syntax in quoted text (Monte)
- fixed bug in $smarty.const.FOO introduced in 2.4.1 (M - fixed bug in $smarty.const.FOO introduced in 2.4.1 (M

View File

@@ -1514,7 +1514,6 @@ class Smarty_Compiler extends Smarty {
} }
foreach ($indexes as $index) { foreach ($indexes as $index) {
if ($index{0} == '[') { if ($index{0} == '[') {
$index = substr($index, 1, -1); $index = substr($index, 1, -1);
if (is_numeric($index)) { if (is_numeric($index)) {
@@ -1538,9 +1537,19 @@ class Smarty_Compiler extends Smarty {
} 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 { } else {
// parse each parameter to the object if(preg_match('!((?:' . $this->_obj_ext_regexp . ')+)(' . $this->_obj_params_regexp . ')?!', $index, $match)) {
if(preg_match('!(?:' . $this->_obj_ext_regexp . ')+(?:(' . $this->_obj_params_regexp . '))?!', $index, $match)) { if(!empty($match[2])) {
$index = str_replace($match[1], $this->_parse_parenth_args($match[1]), $index); // 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;
} }

View File

@@ -1514,7 +1514,6 @@ class Smarty_Compiler extends Smarty {
} }
foreach ($indexes as $index) { foreach ($indexes as $index) {
if ($index{0} == '[') { if ($index{0} == '[') {
$index = substr($index, 1, -1); $index = substr($index, 1, -1);
if (is_numeric($index)) { if (is_numeric($index)) {
@@ -1538,9 +1537,19 @@ class Smarty_Compiler extends Smarty {
} 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 { } else {
// parse each parameter to the object if(preg_match('!((?:' . $this->_obj_ext_regexp . ')+)(' . $this->_obj_params_regexp . ')?!', $index, $match)) {
if(preg_match('!(?:' . $this->_obj_ext_regexp . ')+(?:(' . $this->_obj_params_regexp . '))?!', $index, $match)) { if(!empty($match[2])) {
$index = str_replace($match[1], $this->_parse_parenth_args($match[1]), $index); // 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;
} }