1 | <?php |
||
19 | class ConfigurationGenerator |
||
20 | { |
||
21 | protected $iterator; |
||
22 | protected $queue; |
||
23 | protected $bundle; |
||
24 | protected $className; |
||
25 | protected $namespace; |
||
26 | protected $rootKey; |
||
27 | protected $width = 4; |
||
28 | protected $previousDepth = -1; |
||
29 | |||
30 | /** |
||
31 | * Constructor. |
||
32 | * |
||
33 | * @param array $config |
||
34 | * @param string $className |
||
35 | */ |
||
36 | 3 | public function __construct(array $config, Bundle $bundle, $className = 'Configuration') |
|
43 | |||
44 | /** |
||
45 | * Generates a Configuration file. |
||
46 | * |
||
47 | * @return string |
||
48 | */ |
||
49 | 4 | public function generate() |
|
66 | |||
67 | /** |
||
68 | * Initializes iterator, namespace, rootKey to generate. |
||
69 | * |
||
70 | * @param array $config |
||
71 | */ |
||
72 | 3 | protected function initialize(array $config) |
|
79 | |||
80 | /** |
||
81 | * Whether the ConfigurationGenerator is initialized or not. |
||
82 | * |
||
83 | * @return bool |
||
84 | */ |
||
85 | 4 | protected function initialized() |
|
89 | |||
90 | /** |
||
91 | * Adds an arrayNode start and end code. |
||
92 | * |
||
93 | * adds arrayNode start/end(children(), end()) |
||
94 | * |
||
95 | * @return ConfigurationGenerator |
||
96 | */ |
||
97 | 3 | protected function addArrayNodeOnAndOff() |
|
116 | |||
117 | /** |
||
118 | * Adds an arrayNode or a scalarNode. |
||
119 | * |
||
120 | * @param string $key |
||
121 | * @param mixed $node |
||
122 | * |
||
123 | * @return ConfigurationGenerator |
||
124 | */ |
||
125 | 3 | protected function addNodes($key, $node) |
|
142 | |||
143 | /** |
||
144 | * Post iteration process to add a last end() and a semicolon. |
||
145 | */ |
||
146 | 3 | protected function postIteration() |
|
152 | |||
153 | /** |
||
154 | * Generates a Configuration file string. |
||
155 | * |
||
156 | * @return string |
||
157 | */ |
||
158 | 3 | protected function generateConfiguration() |
|
202 | |||
203 | /** |
||
204 | * Counts an indent and return indented. |
||
205 | * |
||
206 | * @param int $count |
||
207 | * |
||
208 | * @return string |
||
209 | */ |
||
210 | 3 | protected function indent($count) |
|
214 | |||
215 | /** |
||
216 | * Gets an indent count. |
||
217 | * |
||
218 | * @param int|null $depth |
||
219 | * |
||
220 | * @return int |
||
221 | */ |
||
222 | 3 | protected function getIndentCount($depth = null) |
|
228 | |||
229 | /** |
||
230 | * Codes a children(). |
||
231 | * |
||
232 | * @param int $indent |
||
233 | * |
||
234 | * @return string |
||
235 | */ |
||
236 | 3 | protected function codeChildren($indent) |
|
240 | |||
241 | /** |
||
242 | * Codes an end(). |
||
243 | * |
||
244 | * @param int $indent |
||
245 | * |
||
246 | * @return string |
||
247 | */ |
||
248 | 3 | protected function codeEnd($indent) |
|
252 | |||
253 | /** |
||
254 | * Codes end() by current depth. |
||
255 | * |
||
256 | * @param int $currentDepth |
||
257 | */ |
||
258 | 3 | protected function codeEndByCurrentDepth($currentDepth) |
|
266 | |||
267 | /** |
||
268 | * Codes an arrayNode(). |
||
269 | * |
||
270 | * @param int $indent |
||
271 | * @param string $key |
||
272 | * @param string $addCodes |
||
273 | * |
||
274 | * @return string |
||
275 | */ |
||
276 | 3 | protected function codeArrayNode($indent, $key, $addCodes = '') |
|
282 | |||
283 | /** |
||
284 | * Codes an arrayNode() with prototype('scalar'). |
||
285 | * |
||
286 | * @param int $indent |
||
287 | * @param string $key |
||
288 | * |
||
289 | * @return string |
||
290 | */ |
||
291 | 2 | protected function codeArrayNodeWithPrototype($indent, $key) |
|
295 | |||
296 | /** |
||
297 | * Codes an scalarNode(). |
||
298 | * |
||
299 | * @param int $indent |
||
300 | * @param string $key |
||
301 | * |
||
302 | * @return string |
||
303 | */ |
||
304 | 3 | protected function codeScalarNode($indent, $key) |
|
308 | |||
309 | /** |
||
310 | * Codes an semicolon. |
||
311 | * |
||
312 | * @param int $indent |
||
313 | * |
||
314 | * @return string |
||
315 | */ |
||
316 | 3 | protected function codeSemicolon($indent) |
|
320 | |||
321 | /** |
||
322 | * Creates an outer iterator. |
||
323 | * |
||
324 | * @param array $config |
||
325 | * |
||
326 | * @return \RecursiveIteratorIterator |
||
327 | */ |
||
328 | 3 | protected function createIterator(array $config) |
|
334 | |||
335 | /** |
||
336 | * Creates an inner iterator. |
||
337 | * |
||
338 | * @param array $config |
||
339 | * |
||
340 | * @return \RecursiveArrayIterator |
||
341 | */ |
||
342 | 3 | protected function createInnerIterator(array $config) |
|
346 | |||
347 | /** |
||
348 | * Creates a queue. |
||
349 | * |
||
350 | * @return \SplQueue |
||
351 | */ |
||
352 | 3 | protected function createQueue() |
|
356 | } |
||
357 |