minor #9201 [ExpressionLanguage] replaced the =~ operator by matches (removed the != operator) (fabpot)
This PR was merged into the master branch.
Discussion
----------
[ExpressionLanguage] replaced the =~ operator by matches (removed the != operator)
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | n/a
| License | MIT
| Doc PR | n/a
To be consistent with fabpot/Twig#1209
Commits
-------
4c2d2e2
[ExpressionLanguage] replaced the =~ operator by matches (removed the != operator)
This commit is contained in:
commit
c6b3ec2729
@ -38,9 +38,9 @@ class BinaryNode extends Node
|
||||
{
|
||||
$operator = $this->attributes['operator'];
|
||||
|
||||
if ('=~' == $operator || '!~' == $operator) {
|
||||
if ('matches' == $operator) {
|
||||
$compiler
|
||||
->raw(('!~' == $operator ? '!' : '').'preg_match(')
|
||||
->raw('preg_match(')
|
||||
->compile($this->nodes['right'])
|
||||
->raw(', ')
|
||||
->compile($this->nodes['left'])
|
||||
@ -136,7 +136,7 @@ class BinaryNode extends Node
|
||||
return $left / $right;
|
||||
case '%':
|
||||
return $left % $right;
|
||||
case '=~':
|
||||
case 'matches':
|
||||
return preg_match($right, $left);
|
||||
case '!~':
|
||||
return !preg_match($right, $left);
|
||||
|
@ -60,6 +60,7 @@ class Parser
|
||||
'<=' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'not in' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'in' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'matches' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'..' => array('precedence' => 25, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'+' => array('precedence' => 30, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'-' => array('precedence' => 30, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
@ -67,8 +68,6 @@ class Parser
|
||||
'*' => array('precedence' => 60, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'/' => array('precedence' => 60, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'%' => array('precedence' => 60, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'=~' => array('precedence' => 70, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'!~' => array('precedence' => 70, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'**' => array('precedence' => 200, 'associativity' => Parser::OPERATOR_RIGHT),
|
||||
);
|
||||
}
|
||||
|
@ -62,8 +62,7 @@ class BinaryNodeTest extends AbstractNodeTest
|
||||
|
||||
array(array(1, 2, 3), new BinaryNode('..', new ConstantNode(1), new ConstantNode(3))),
|
||||
|
||||
array(1, new BinaryNode('=~', new ConstantNode('abc'), new ConstantNode('/^[a-z]+$/'))),
|
||||
array(false, new BinaryNode('!~', new ConstantNode('abc'), new ConstantNode('/^[a-z]+$/'))),
|
||||
array(1, new BinaryNode('matches', new ConstantNode('abc'), new ConstantNode('/^[a-z]+$/'))),
|
||||
);
|
||||
}
|
||||
|
||||
@ -112,8 +111,7 @@ class BinaryNodeTest extends AbstractNodeTest
|
||||
|
||||
array('range(1, 3)', new BinaryNode('..', new ConstantNode(1), new ConstantNode(3))),
|
||||
|
||||
array('preg_match("/^[a-z]+/i\$/", "abc")', new BinaryNode('=~', new ConstantNode('abc'), new ConstantNode('/^[a-z]+/i$/'))),
|
||||
array('!preg_match("/^[a-z]+\$/", "abc")', new BinaryNode('!~', new ConstantNode('abc'), new ConstantNode('/^[a-z]+$/'))),
|
||||
array('preg_match("/^[a-z]+/i\$/", "abc")', new BinaryNode('matches', new ConstantNode('abc'), new ConstantNode('/^[a-z]+/i$/'))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user