Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc1d11d7

Browse files
[ExpressionLanguage] Add a way to hook on each node when dumping the AST
1 parentf400f01 commitc1d11d7

File tree

16 files changed

+105
-98
lines changed

16 files changed

+105
-98
lines changed

‎src/Symfony/Component/ExpressionLanguage/Node/ArgumentsNode.php‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ public function compile(Compiler $compiler)
2727

2828
publicfunctiondump()
2929
{
30-
$str ='';
30+
$tokens =array();
3131

3232
foreach ($this->getKeyValuePairs()as$pair) {
33-
$str .=sprintf('%s,',$pair['value']->dump());
33+
$tokens[] =',';
34+
$tokens[] =$pair['value'];
3435
}
36+
array_shift($tokens);
3537

36-
returnrtrim($str,',');
38+
return$tokens;
3739
}
3840
}

‎src/Symfony/Component/ExpressionLanguage/Node/ArrayNode.php‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,30 @@ public function dump()
6262
{
6363
$array =array();
6464
foreach ($this->getKeyValuePairs()as$pair) {
65-
$array[$pair['key']->attributes['value']] =$pair['value']->dump();
65+
$array[$pair['key']->attributes['value']] =$pair['value'];
6666
}
6767

68+
$tokens =array();
69+
6870
if ($this->isHash($array)) {
69-
$str ='{';
70-
71-
foreach ($arrayas$key =>$value) {
72-
if (is_int($key)) {
73-
$str .=sprintf('%s: %s,',$key,$value);
74-
}else {
75-
$str .=sprintf('"%s": %s,',$this->dumpEscaped($key),$value);
76-
}
71+
foreach ($arrayas$k =>$v) {
72+
$tokens[] =',';
73+
$tokens[] =newConstantNode($k);
74+
$tokens[] =':';
75+
$tokens[] =$v;
7776
}
78-
79-
returnrtrim($str,',').'}';
80-
}
81-
82-
$str ='[';
83-
84-
foreach ($arrayas$key =>$value) {
85-
$str .=sprintf('%s,',$value);
77+
$tokens[0] ='{';
78+
$tokens[] ='}';
79+
}else {
80+
foreach ($arrayas$v) {
81+
$tokens[] =',';
82+
$tokens[] =$v;
83+
}
84+
$tokens[0] ='[';
85+
$tokens[] =']';
8686
}
8787

88-
returnrtrim($str,',').']';
88+
return$tokens;
8989
}
9090

9191
protectedfunctiongetKeyValuePairs()

‎src/Symfony/Component/ExpressionLanguage/Node/BinaryNode.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,6 @@ public function evaluate($functions, $values)
157157

158158
publicfunctiondump()
159159
{
160-
returnsprintf('(%s %s %s)',$this->nodes['left']->dump(),$this->attributes['operator'],$this->nodes['right']->dump());
160+
returnarray('(',$this->nodes['left'],''.$this->attributes['operator'].'',$this->nodes['right'],')');
161161
}
162162
}

‎src/Symfony/Component/ExpressionLanguage/Node/ConditionalNode.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ public function evaluate($functions, $values)
5151

5252
publicfunctiondump()
5353
{
54-
returnsprintf('(%s ? %s : %s)',$this->nodes['expr1']->dump(),$this->nodes['expr2']->dump(),$this->nodes['expr3']->dump());
54+
returnarray('(',$this->nodes['expr1'],' ?',$this->nodes['expr2'],' :',$this->nodes['expr3'],')');
5555
}
5656
}

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

Lines changed: 31 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -40,49 +40,37 @@ public function evaluate($functions, $values)
4040

4141
publicfunctiondump()
4242
{
43-
return$this->dumpValue($this->attributes['value']);
44-
}
45-
46-
privatefunctiondumpValue($value)
47-
{
48-
switch (true) {
49-
casetrue ===$value:
50-
return'true';
51-
52-
casefalse ===$value:
53-
return'false';
54-
55-
casenull ===$value:
56-
return'null';
57-
58-
caseis_numeric($value):
59-
return$value;
60-
61-
caseis_array($value):
62-
if ($this->isHash($value)) {
63-
$str ='{';
64-
65-
foreach ($valueas$key =>$v) {
66-
if (is_int($key)) {
67-
$str .=sprintf('%s: %s,',$key,$this->dumpValue($v));
68-
}else {
69-
$str .=sprintf('"%s": %s,',$this->dumpEscaped($key),$this->dumpValue($v));
70-
}
71-
}
72-
73-
returnrtrim($str,',').'}';
74-
}
75-
76-
$str ='[';
77-
78-
foreach ($valueas$key =>$v) {
79-
$str .=sprintf('%s,',$this->dumpValue($v));
80-
}
81-
82-
returnrtrim($str,',').']';
83-
84-
default:
85-
returnsprintf('"%s"',$this->dumpEscaped($value));
43+
$tokens =array();
44+
$value =$this->attributes['value'];
45+
46+
if (true ===$value) {
47+
$tokens[] ='true';
48+
}elseif (false ===$value) {
49+
$tokens[] ='false';
50+
}elseif (null ===$value) {
51+
$tokens[] ='null';
52+
}elseif (is_numeric($value)) {
53+
$tokens[] =$value;
54+
}elseif (!is_array($value)) {
55+
$tokens[] =$this->dumpString($value);
56+
}elseif ($this->isHash($value)) {
57+
foreach ($valueas$k =>$v) {
58+
$tokens[] =',';
59+
$tokens[] =newConstantNode($k);
60+
$tokens[] =':';
61+
$tokens[] =newConstantNode($v);
62+
}
63+
$tokens[0] ='{';
64+
$tokens[] ='}';
65+
}else {
66+
foreach ($valueas$v) {
67+
$tokens[] =',';
68+
$tokens[] =newConstantNode($v);
69+
}
70+
$tokens[0] ='[';
71+
$tokens[] =']';
8672
}
73+
74+
return$tokens;
8775
}
8876
}

‎src/Symfony/Component/ExpressionLanguage/Node/FunctionNode.php‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,16 @@ public function evaluate($functions, $values)
5252

5353
publicfunctiondump()
5454
{
55-
$str =$this->attributes['name'];
56-
57-
$str .='(';
55+
$tokens =array();
56+
$tokens[] =$this->attributes['name'];
5857

5958
foreach ($this->nodes['arguments']->nodesas$node) {
60-
$str .=$node->dump().',';
59+
$tokens[] =',';
60+
$tokens[] =$node;
6161
}
62+
$tokens[1] ='(';
63+
$tokens[] =')';
6264

63-
returnrtrim($str,',').')';
65+
return$tokens;
6466
}
6567
}

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

Lines changed: 7 additions & 7 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['value'])
42+
->raw($this->nodes['attribute']->attributes['name'])
4343
;
4444
break;
4545

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

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

7878
return$obj->$property;
7979

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

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

8888
caseself::ARRAY_CALL:
8989
$array =$this->nodes['node']->evaluate($functions,$values);
@@ -99,13 +99,13 @@ public function dump()
9999
{
100100
switch ($this->attributes['type']) {
101101
caseself::PROPERTY_CALL:
102-
returnsprintf('%s.%s',$this->nodes['node']->dump(),trim($this->nodes['attribute']->dump(),'"'));
102+
returnarray($this->nodes['node'],'.',$this->nodes['attribute']);
103103

104104
caseself::METHOD_CALL:
105-
returnsprintf('%s.%s(%s)',$this->nodes['node']->dump(),trim($this->nodes['attribute']->dump(),'"'),$this->nodes['arguments']->dump());
105+
returnarray($this->nodes['node'],'.',$this->nodes['attribute'],'(',$this->nodes['arguments'],')');
106106

107107
caseself::ARRAY_CALL:
108-
returnsprintf('%s[%s]',$this->nodes['node']->dump(),$this->nodes['attribute']->dump());
108+
returnarray($this->nodes['node'],'[',$this->nodes['attribute'],']');
109109
}
110110
}
111111
}

‎src/Symfony/Component/ExpressionLanguage/Node/NameNode.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ public function evaluate($functions, $values)
4040

4141
publicfunctiondump()
4242
{
43-
return$this->attributes['name'];
43+
returnarray($this->attributes['name']);
4444
}
4545
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ public function dump()
8181
thrownew \BadMethodCallException(sprintf('Dumping a "%s" instance is not supported yet.',get_class($this)));
8282
}
8383

84-
protectedfunctiondumpEscaped($value)
84+
protectedfunctiondumpString($value)
8585
{
86-
returnstr_replace(array('\\','"'),array('\\\\','\"'),$value);
86+
returnsprintf('"%s"',addcslashes($value,"\0\t\"\\"));
8787
}
8888

8989
protectedfunctionisHash(array$value)

‎src/Symfony/Component/ExpressionLanguage/Node/UnaryNode.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ public function evaluate($functions, $values)
6161

6262
publicfunctiondump()
6363
{
64-
returnsprintf('(%s %s)',$this->attributes['operator'],$this->nodes['node']->dump());
64+
returnarray('(',$this->attributes['operator'].'',$this->nodes['node'],')');
6565
}
6666
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp