1
1
<?php
2
2
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
3
12
namespace Symfony \Component \Config \Definition ;
4
13
5
14
/**
@@ -18,7 +27,7 @@ public function dump(ConfigurationInterface $configuration)
18
27
return $ this ->dumpNode ($ configuration ->getConfigTreeBuilder ()->buildTree ());
19
28
}
20
29
21
- public function dumpNode (NodeInterface $ node )
30
+ public function dumpNode (NodeInterface $ node )
22
31
{
23
32
$ this ->reference = '' ;
24
33
$ this ->writeNode ($ node );
@@ -32,108 +41,108 @@ public function dumpNode(NodeInterface $node)
32
41
* @param int $depth
33
42
*/
34
43
private function writeNode (NodeInterface $ node , $ depth = 0 )
35
- {
36
- $ comments = array ();
37
- $ default = '' ;
38
- $ defaultArray = null ;
39
- $ children = null ;
40
- $ example = $ node ->getExample ();
41
-
42
- // defaults
43
- if ($ node instanceof ArrayNode) {
44
- $ children = $ node ->getChildren ();
45
-
46
- if ($ node instanceof PrototypedArrayNode) {
47
- $ prototype = $ node ->getPrototype ();
48
-
49
- if ($ prototype instanceof ArrayNode) {
50
- $ children = $ prototype ->getChildren ();
51
- }
52
-
53
- // check for attribute as key
54
- if ($ key = $ node ->getKeyAttribute ()) {
55
- $ keyNode = new ArrayNode ($ key , $ node );
56
- $ keyNode ->setInfo ('Prototype ' );
57
-
58
- // add children
59
- foreach ($ children as $ childNode ) {
60
- $ keyNode ->addChild ($ childNode );
61
- }
62
- $ children = array ($ key => $ keyNode );
63
- }
64
- }
65
-
66
- if (!$ children ) {
67
- if ($ node ->hasDefaultValue () && count ($ defaultArray = $ node ->getDefaultValue ())) {
68
- $ default = '' ;
69
- } elseif (!is_array ($ example )) {
70
- $ default = '[] ' ;
71
- }
72
- }
73
- } else {
74
- $ default = '~ ' ;
75
-
76
- if ($ node ->hasDefaultValue ()) {
77
- $ default = $ node ->getDefaultValue ();
78
-
79
- if (true === $ default ) {
80
- $ default = 'true ' ;
81
- } elseif (false === $ default ) {
82
- $ default = 'false ' ;
83
- } elseif (null === $ default ) {
84
- $ default = '~ ' ;
85
- }
86
- }
87
- }
88
-
89
- // required?
90
- if ($ node ->isRequired ()) {
91
- $ comments [] = 'Required ' ;
92
- }
93
-
94
- // example
95
- if ($ example && !is_array ($ example )) {
96
- $ comments [] = 'Example: ' .$ example ;
97
- }
98
-
99
- $ default = (string ) $ default != '' ? ' ' .$ default : '' ;
100
- $ comments = count ($ comments ) ? '# ' .implode (', ' , $ comments ) : '' ;
101
-
102
- $ text = sprintf ('%-20s %s %s ' , $ node ->getName ().': ' , $ default , $ comments );
103
-
104
- if ($ info = $ node ->getInfo ()) {
105
- $ this ->writeLine ('' );
106
- $ this ->writeLine ('# ' .$ info , $ depth * 4 );
107
- }
108
-
109
- $ this ->writeLine ($ text , $ depth * 4 );
110
-
111
- // output defaults
112
- if ($ defaultArray ) {
113
- $ this ->writeLine ('' );
114
-
115
- $ message = count ($ defaultArray ) > 1 ? 'Defaults ' : 'Default ' ;
116
-
117
- $ this ->writeLine ('# ' .$ message .': ' , $ depth * 4 + 4 );
118
-
119
- $ this ->writeArray ($ defaultArray , $ depth + 1 );
120
- }
121
-
122
- if (is_array ($ example )) {
123
- $ this ->writeLine ('' );
124
-
125
- $ message = count ($ example ) > 1 ? 'Examples ' : 'Example ' ;
126
-
127
- $ this ->writeLine ('# ' .$ message .': ' , $ depth * 4 + 4 );
128
-
129
- $ this ->writeArray ($ example , $ depth + 1 );
130
- }
131
-
132
- if ($ children ) {
133
- foreach ($ children as $ childNode ) {
134
- $ this ->writeNode ($ childNode , $ depth + 1 );
135
- }
136
- }
44
+ {
45
+ $ comments = array ();
46
+ $ default = '' ;
47
+ $ defaultArray = null ;
48
+ $ children = null ;
49
+ $ example = $ node ->getExample ();
50
+
51
+ // defaults
52
+ if ($ node instanceof ArrayNode) {
53
+ $ children = $ node ->getChildren ();
54
+
55
+ if ($ node instanceof PrototypedArrayNode) {
56
+ $ prototype = $ node ->getPrototype ();
57
+
58
+ if ($ prototype instanceof ArrayNode) {
59
+ $ children = $ prototype ->getChildren ();
60
+ }
61
+
62
+ // check for attribute as key
63
+ if ($ key = $ node ->getKeyAttribute ()) {
64
+ $ keyNode = new ArrayNode ($ key , $ node );
65
+ $ keyNode ->setInfo ('Prototype ' );
66
+
67
+ // add children
68
+ foreach ($ children as $ childNode ) {
69
+ $ keyNode ->addChild ($ childNode );
70
+ }
71
+ $ children = array ($ key => $ keyNode );
72
+ }
73
+ }
74
+
75
+ if (!$ children ) {
76
+ if ($ node ->hasDefaultValue () && count ($ defaultArray = $ node ->getDefaultValue ())) {
77
+ $ default = '' ;
78
+ } elseif (!is_array ($ example )) {
79
+ $ default = '[] ' ;
80
+ }
81
+ }
82
+ } else {
83
+ $ default = '~ ' ;
84
+
85
+ if ($ node ->hasDefaultValue ()) {
86
+ $ default = $ node ->getDefaultValue ();
87
+
88
+ if (true === $ default ) {
89
+ $ default = 'true ' ;
90
+ } elseif (false === $ default ) {
91
+ $ default = 'false ' ;
92
+ } elseif (null === $ default ) {
93
+ $ default = '~ ' ;
94
+ }
95
+ }
96
+ }
97
+
98
+ // required?
99
+ if ($ node ->isRequired ()) {
100
+ $ comments [] = 'Required ' ;
101
+ }
102
+
103
+ // example
104
+ if ($ example && !is_array ($ example )) {
105
+ $ comments [] = 'Example: ' .$ example ;
106
+ }
107
+
108
+ $ default = (string ) $ default != '' ? ' ' .$ default : '' ;
109
+ $ comments = count ($ comments ) ? '# ' .implode (', ' , $ comments ) : '' ;
110
+
111
+ $ text = sprintf ('%-20s %s %s ' , $ node ->getName ().': ' , $ default , $ comments );
112
+
113
+ if ($ info = $ node ->getInfo ()) {
114
+ $ this ->writeLine ('' );
115
+ $ this ->writeLine ('# ' .$ info , $ depth * 4 );
116
+ }
117
+
118
+ $ this ->writeLine ($ text , $ depth * 4 );
119
+
120
+ // output defaults
121
+ if ($ defaultArray ) {
122
+ $ this ->writeLine ('' );
123
+
124
+ $ message = count ($ defaultArray ) > 1 ? 'Defaults ' : 'Default ' ;
125
+
126
+ $ this ->writeLine ('# ' .$ message .': ' , $ depth * 4 + 4 );
127
+
128
+ $ this ->writeArray ($ defaultArray , $ depth + 1 );
129
+ }
130
+
131
+ if (is_array ($ example )) {
<
B91C
/td>
132
+ $ this ->writeLine ('' );
133
+
134
+ $ message = count ($ example ) > 1 ? 'Examples ' : 'Example ' ;
135
+
136
+ $ this ->writeLine ('# ' .$ message .': ' , $ depth * 4 + 4 );
137
+
138
+ $ this ->writeArray ($ example , $ depth + 1 );
139
+ }
140
+
141
+ if ($ children ) {
142
+ foreach ($ children as $ childNode ) {
143
+ $ this ->writeNode ($ childNode , $ depth + 1 );
144
+ }
145
+ }
137
146
}
138
147
139
148
/**
@@ -172,4 +181,4 @@ private function writeArray(array $array, $depth)
172
181
}
173
182
}
174
183
}
175
- }
184
+ }
0 commit comments