1 | <?php |
||
5 | class RoutingNormalizer |
||
6 | { |
||
7 | /** |
||
8 | * Normalizes string and array declarations into associative array. |
||
9 | * |
||
10 | * @param string|array $declaration |
||
11 | * |
||
12 | * @return array |
||
13 | */ |
||
14 | public function normalizeDeclaration($declaration) |
||
15 | { |
||
16 | if (is_string($declaration)) { |
||
17 | return $this->normalizeString($declaration); |
||
18 | } |
||
19 | |||
20 | // Normalize numerically indexed array |
||
21 | if (array_keys($declaration) === array_keys(array_values($declaration))) { |
||
22 | return $this->normalizeArray($declaration); |
||
23 | } |
||
24 | |||
25 | // Adds default value to associative array |
||
26 | return array_merge(['required' => true, 'arguments' => []], $declaration); |
||
27 | } |
||
28 | |||
29 | private function normalizeString($declaration) |
||
30 | { |
||
31 | $service = $declaration; |
||
32 | $method = null; |
||
33 | |||
34 | if (strpos($declaration, ':') !== false) { |
||
35 | list($service, $method) = explode(':', $declaration); |
||
36 | } |
||
37 | |||
38 | return [ |
||
39 | 'service' => $service, |
||
40 | 'method' => $method, |
||
41 | 'arguments' => [], |
||
42 | 'required' => true, |
||
43 | ]; |
||
44 | } |
||
45 | |||
46 | private function normalizeArray($declaration) |
||
64 | } |
||
65 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.