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

Commit66d23db

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

File tree

16 files changed

+116
-109
lines changed

16 files changed

+116
-109
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@ public function compile(Compiler $compiler)
2525
$this->compileArguments($compiler,false);
2626
}
2727

28-
publicfunctiondump()
28+
publicfunctiontoArray()
2929
{
30-
$str ='';
30+
$array =array();
3131

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

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

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,34 +58,34 @@ public function evaluate($functions, $values)
5858
return$result;
5959
}
6060

61-
publicfunctiondump()
61+
publicfunctiontoArray()
6262
{
63-
$array =array();
63+
$value =array();
6464
foreach ($this->getKeyValuePairs()as$pair) {
65-
$array[$pair['key']->attributes['value']] =$pair['value']->dump();
65+
$value[$pair['key']->attributes['value']] =$pair['value'];
6666
}
6767

68-
if ($this->isHash($array)) {
69-
$str ='{';
68+
$array =array();
7069

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-
}
70+
if ($this->isHash($value)) {
71+
foreach ($valueas$k =>$v) {
72+
$array[] =',';
73+
$array[] =newConstantNode($k);
74+
$array[] =':';
75+
$array[] =$v;
7776
}
78-
79-
returnrtrim($str,',').'}';
80-
}
81-
82-
$str ='[';
83-
84-
foreach ($arrayas$key =>$value) {
85-
$str .=sprintf('%s,',$value);
77+
$array[0] ='{';
78+
$array[] ='}';
79+
}else {
80+
foreach ($valueas$v) {
81+
$array[] =',';
82+
$array[] =$v;
83+
}
84+
$array[0] ='[';
85+
$array[] =']';
8686
}
8787

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

9191
protectedfunctiongetKeyValuePairs()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ public function evaluate($functions, $values)
155155
}
156156
}
157157

158-
publicfunctiondump()
158+
publicfunctiontoArray()
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public function evaluate($functions, $values)
4949
return$this->nodes['expr3']->evaluate($functions,$values);
5050
}
5151

52-
publicfunctiondump()
52+
publicfunctiontoArray()
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: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -38,51 +38,39 @@ public function evaluate($functions, $values)
3838
return$this->attributes['value'];
3939
}
4040

41-
publicfunctiondump()
41+
publicfunctiontoArray()
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+
$array =array();
44+
$value =$this->attributes['value'];
45+
46+
if (true ===$value) {
47+
$array[] ='true';
48+
}elseif (false ===$value) {
49+
$array[] ='false';
50+
}elseif (null ===$value) {
51+
$array[] ='null';
52+
}elseif (is_numeric($value)) {
53+
$array[] =$value;
54+
}elseif (!is_array($value)) {
55+
$array[] =$this->dumpString($value);
56+
}elseif ($this->isHash($value)) {
57+
foreach ($valueas$k =>$v) {
58+
$array[] =',';
59+
$array[] =newself($k);
60+
$array[] =':';
61+
$array[] =newself($v);
62+
}
63+
$array[0] ='{';
64+
$array[] ='}';
65+
}else {
66+
foreach ($valueas$v) {
67+
$array[] =',';
68+
$array[] =newself($v);
69+
}
70+
$array[0] ='[';
71+
$array[] =']';
8672
}
73+
74+
return$array;
8775
}
8876
}

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,18 @@ public function evaluate($functions, $values)
5050
returncall_user_func_array($functions[$this->attributes['name']]['evaluator'],$arguments);
5151
}
5252

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

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

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

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

Lines changed: 8 additions & 8 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);
@@ -95,17 +95,17 @@ public function evaluate($functions, $values)
9595
}
9696
}
9797

98-
publicfunctiondump()
98+
publicfunctiontoArray()
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public function evaluate($functions, $values)
3838
return$values[$this->attributes['name']];
3939
}
4040

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ public function evaluate($functions, $values)
7676
return$results;
7777
}
7878

79-
publicfunctiondump()
79+
publicfunctiontoArray()
8080
{
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public function evaluate($functions, $values)
5959
return$value;
6060
}
6161

62-
publicfunctiondump()
62+
publicfunctiontoArray()
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