mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 20:06:31 +00:00
made it possible to use named operators as variables
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
* 1.14.1 (2013-XX-XX)
|
||||
|
||||
* made it possible to use named operators as variables
|
||||
* fixed the possibility to have a variable named 'matches'
|
||||
* added support for PHP 5.5 DateTimeInterface
|
||||
|
||||
|
||||
@@ -162,9 +162,10 @@ class Twig_ExpressionParser
|
||||
break;
|
||||
|
||||
case Twig_Token::OPERATOR_TYPE:
|
||||
if ('matches' == $token->getValue()) {
|
||||
if (preg_match(Twig_Lexer::REGEX_NAME, $token->getValue(), $matches) && $matches[0] == $token->getValue()) {
|
||||
// in this context, string operators are variable names
|
||||
$this->parser->getStream()->next();
|
||||
$node = new Twig_Node_Expression_Name('matches', $token->getLine());
|
||||
$node = new Twig_Node_Expression_Name($token->getValue(), $token->getLine());
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
--TEST--
|
||||
Twig allows to use named operators as variable names
|
||||
--TEMPLATE--
|
||||
{% for match in matches %}
|
||||
{{- match }}
|
||||
{% endfor %}
|
||||
{{ in }}
|
||||
{{ is }}
|
||||
--DATA--
|
||||
return array('matches' => array(1, 2, 3), 'in' => 'in', 'is' => 'is')
|
||||
--EXPECT--
|
||||
1
|
||||
2
|
||||
3
|
||||
in
|
||||
is
|
||||
@@ -0,0 +1,8 @@
|
||||
--TEST--
|
||||
Twig does not allow to use two-word named operators as variable names
|
||||
--TEMPLATE--
|
||||
{{ starts with }}
|
||||
--DATA--
|
||||
return array()
|
||||
--EXCEPTION--
|
||||
Twig_Error_Syntax: Unexpected token "operator" of value "starts with" in "index.twig" at line 2
|
||||
@@ -1,12 +0,0 @@
|
||||
--TEST--
|
||||
Twig allows to use 'matches' for a variable name
|
||||
--TEMPLATE--
|
||||
{% for match in matches %}
|
||||
{{- match }}
|
||||
{% endfor %}
|
||||
--DATA--
|
||||
return array('matches' => array(1, 2, 3))
|
||||
--EXPECT--
|
||||
1
|
||||
2
|
||||
3
|
||||
Reference in New Issue
Block a user