Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b00930f

Browse files
committed
[ExpressionLanguage] fixed a BC break
1 parent 36c399f commit b00930f

File tree

6 files changed

+22
-18
lines changed

6 files changed

+22
-18
lines changed

src/Symfony/Component/ExpressionLanguage/Node/ConstantNode.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020
*/
2121
class ConstantNode extends Node
2222
{
23-
public function __construct($value)
23+
private $isIdentifier;
24+
25+
public function __construct($value, $isIdentifier = false)
2426
{
27+
$this->isIdentifier = $isIdentifier;
2528
parent::__construct(
2629
array(),
2730
array('value' => $value)
@@ -43,7 +46,9 @@ public function toArray()
4346
$array = array();
4447
$value = $this->attributes['value'];
4548

46-
if (true === $value) {
49+
if ($this->isIdentifier) {
50+
$array[] = $value;
51+
} elseif (true === $value) {
4752
$array[] = 'true';
4853
} elseif (false === $value) {
4954
$array[] = 'false';

src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ public function compile(Compiler $compiler)
3939
$compiler
4040
->compile($this->nodes['node'])
4141
->raw('->')
42-
->raw($this->nodes['attribute']->attributes['name'])
42+
->raw($this->nodes['attribute']->attributes['value'])
4343
;
4444
break;
4545

4646
case self::METHOD_CALL:
4747
$compiler
4848
->compile($this->nodes['node'])
4949
->raw('->')
50-
->raw($this->nodes['attribute']->attributes['name'])
50+
->raw($this->nodes['attribute']->attributes['value'])
5151
->raw('(')
5252
->compile($this->nodes['arguments'])
5353
->raw(')')
@@ -73,7 +73,7 @@ public function evaluate($functions, $values)
7373
throw new \RuntimeException('Unable to get a property on a non-object.');
7474
}
7575

76-
$property = $this->nodes['attribute']->attributes['name'];
76+
$property = $this->nodes['attribute']->attributes['value'];
7777

7878
return $obj->$property;
7979

@@ -83,7 +83,7 @@ public function evaluate($functions, $values)
8383
throw new \RuntimeException('Unable to get a property on a non-object.');
8484
}
8585

86-
return call_user_func_array(array($obj, $this->nodes['attribute']->attributes['name']), $this->nodes['arguments']->evaluate($functions, $values));
86+
return call_user_func_array(array($obj, $this->nodes['attribute']->attributes['value']), $this->nodes['arguments']->evaluate($functions, $values));
8787

8888
case self::ARRAY_CALL:
8989
$array = $this->nodes['node']->evaluate($functions, $values);

src/Symfony/Component/ExpressionLanguage/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ public function parsePostfixExpression($node)
330330
throw new SyntaxError('Expected name', $token->cursor);
331331
}
332332

333-
$arg = new Node\NameNode($token->value);
333+
$arg = new Node\ConstantNode($token->value, true);
334334

335335
$arguments = new Node\ArgumentsNode();
336336
if ($this->stream->current->test(Token::PUNCTUATION_TYPE, '(')) {

src/Symfony/Component/ExpressionLanguage/Tests/Node/ConstantNodeTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function getDumpData()
5050
array('3', new ConstantNode(3)),
5151
array('3.3', new ConstantNode(3.3)),
5252
array('"foo"', new ConstantNode('foo')),
53+
array('foo', new ConstantNode('foo', true)),
5354
array('{0: 1, "b": "a", 1: true}', new ConstantNode(array(1, 'b' => 'a', true))),
5455
array('{"a\\"b": "c", "a\\\\b": "d"}', new ConstantNode(array('a"b' => 'c', 'a\\b' => 'd'))),
5556
array('["c", "d"]', new ConstantNode(array('c', 'd'))),

src/Symfony/Component/ExpressionLanguage/Tests/Node/GetAttrNodeTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public function getEvaluateData()
2424
array('b', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), $this->getArrayNode(), GetAttrNode::ARRAY_CALL), array('foo' => array('b' => 'a', 'b'))),
2525
array('a', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), $this->getArrayNode(), GetAttrNode::ARRAY_CALL), array('foo' => array('b' => 'a', 'b'))),
2626

27-
array('bar', new GetAttrNode(new NameNode('foo'), new NameNode('foo'), $this->getArrayNode(), GetAttrNode::PROPERTY_CALL), array('foo' => new Obj())),
27+
array('bar', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), $this->getArrayNode(), GetAttrNode::PROPERTY_CALL), array('foo' => new Obj())),
2828

29-
array('baz', new GetAttrNode(new NameNode('foo'), new NameNode('foo'), $this->getArrayNode(), GetAttrNode::METHOD_CALL), array('foo' => new Obj())),
29+
array('baz', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), $this->getArrayNode(), GetAttrNode::METHOD_CALL), array('foo' => new Obj())),
3030
array('a', new GetAttrNode(new NameNode('foo'), new NameNode('index'), $this->getArrayNode(), GetAttrNode::ARRAY_CALL), array('foo' => array('b' => 'a', 'b'), 'index' => 'b')),
3131
);
3232
}
@@ -37,9 +37,9 @@ public function getCompileData()
3737
array('$foo[0]', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), $this->getArrayNode(), GetAttrNode::ARRAY_CALL)),
3838
array('$foo["b"]', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), $this->getArrayNode(), GetAttrNode::ARRAY_CALL)),
3939

40-
array('$foo->foo', new GetAttrNode(new NameNode('foo'), new NameNode('foo'), $this->getArrayNode(), GetAttrNode::PROPERTY_CALL), array('foo' => new Obj())),
40+
array('$foo->foo', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), $this->getArrayNode(), GetAttrNode::PROPERTY_CALL), array('foo' => new Obj())),
4141

42-
array('$foo->foo(array("b" => "a", 0 => "b"))', new GetAttrNode(new NameNode('foo'), new NameNode('foo'), $this->getArrayNode(), GetAttrNode::METHOD_CALL), array('foo' => new Obj())),
42+
array('$foo->foo(array("b" => "a", 0 => "b"))', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), $this->getArrayNode(), GetAttrNode::METHOD_CALL), array('foo' => new Obj())),
4343
array('$foo[$index]', new GetAttrNode(new NameNode('foo'), new NameNode('index'), $this->getArrayNode(), GetAttrNode::ARRAY_CALL)),
4444
);
4545
}

src/Symfony/Component/ExpressionLanguage/Tests/ParserTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,24 +98,24 @@ public function getParseData()
9898
'(3 - 3) * 2',
9999
),
100100
array(
101-
new Node\GetAttrNode(new Node\NameNode('foo'), new Node\NameNode('bar'), new Node\ArgumentsNode(), Node\GetAttrNode::PROPERTY_CALL),
101+
new Node\GetAttrNode(new Node\NameNode('foo'), new Node\ConstantNode('bar', true), new Node\ArgumentsNode(), Node\GetAttrNode::PROPERTY_CALL),
102102
'foo.bar',
103103
array('foo'),
104104
),
105105
array(
106-
new Node\GetAttrNode(new Node\NameNode('foo'), new Node\NameNode('bar'), new Node\ArgumentsNode(), Node\GetAttrNode::METHOD_CALL),
106+
new Node\GetAttrNode(new Node\NameNode('foo'), new Node\ConstantNode('bar', true), new Node\ArgumentsNode(), Node\GetAttrNode::METHOD_CALL),
107107
'foo.bar()',
108108
array('foo'),
109109
),
110110
array(
111-
new Node\GetAttrNode(new Node\NameNode('foo'), new Node\NameNode('not'), new Node\ArgumentsNode(), Node\GetAttrNode::METHOD_CALL),
111+
new Node\GetAttrNode(new Node\NameNode('foo'), new Node\ConstantNode('not', true), new Node\ArgumentsNode(), Node\GetAttrNode::METHOD_CALL),
112112
'foo.not()',
113113
array('foo'),
114114
),
115115
array(
116116
new Node\GetAttrNode(
117117
new Node\NameNode('foo'),
118-
new Node\NameNode('bar'),
118+
new Node\ConstantNode('bar', true),
119119
$arguments,
120120
Node\GetAttrNode::METHOD_CALL
121121
),
@@ -159,9 +159,7 @@ public function getParseData()
159159

160160
private function createGetAttrNode($node, $item, $type)
161161
{
162-
$attr = Node\GetAttrNode::ARRAY_CALL === $type ? new Node\ConstantNode($item) : new Node\NameNode($item);
163-
164-
return new Node\GetAttrNode($node, $attr, new Node\ArgumentsNode(), $type);
162+
return new Node\GetAttrNode($node, new Node\ConstantNode($item, Node\GetAttrNode::ARRAY_CALL !== $type), new Node\ArgumentsNode(), $type);
165163
}
166164

167165
/**

0 commit comments

Comments
 (0)