1 | <?php |
||
8 | class L10nCatalogueHelper |
||
9 | { |
||
10 | const LOCALE_KEY = 'locale'; |
||
11 | const VALUE_KEY = 'value'; |
||
12 | |||
13 | /** |
||
14 | * Transforms the config into a two dimensional array where a final element is a boolean, string or numeric value or |
||
15 | * an array of translations. |
||
16 | * This is done by grouping first keys with dots in order to create |
||
17 | * the idResource. The idLocalization is kept. |
||
18 | * |
||
19 | * It drops the elements that do not have the good structure. |
||
20 | * |
||
21 | * @param array $config |
||
22 | * @param string $prefixKey |
||
23 | * |
||
24 | * @return array |
||
25 | */ |
||
26 | 5 | public function createCatalogue($config, $prefixKey = null) |
|
47 | |||
48 | /** |
||
49 | * Returns the level of the given config. |
||
50 | * The level is 0 if the config is a leaf. |
||
51 | * The level of an array is the max of the level of its elements plus one. |
||
52 | * |
||
53 | * @param array $config |
||
54 | * |
||
55 | * @return integer |
||
56 | */ |
||
57 | 5 | private function configLevel($config) |
|
65 | |||
66 | /** |
||
67 | * Returns true if the given config is a leaf. |
||
68 | * A leaf is either a boolean, string or numeric value or a non associative array. |
||
69 | * |
||
70 | * @param mixed $config |
||
71 | * |
||
72 | * @return boolean |
||
73 | */ |
||
74 | 5 | private function isLeaf($config) |
|
84 | |||
85 | /** |
||
86 | * @param array $flatArray |
||
87 | * @param array $config |
||
88 | * @param string $prefixKey |
||
89 | * |
||
90 | * @return array |
||
91 | */ |
||
92 | 2 | private function createResource(array $flatArray, array $config, $prefixKey) |
|
103 | |||
104 | /** |
||
105 | * Formats the given array to be in the format of a catalogue resource. |
||
106 | * A catalogue resource is the value (array) corresponding to a reource id. |
||
107 | * The format is an associative array of value. |
||
108 | * A value is either a boolean, string or numeric value or an associative array where each value is a boolean, |
||
109 | * string or numeric value. |
||
110 | * |
||
111 | * The value that cannot be matched in this format are dropped. |
||
112 | * |
||
113 | * @param array $rawResourceArray |
||
114 | * |
||
115 | * @return array |
||
116 | */ |
||
117 | 2 | private function formatResource(array $rawResourceArray) |
|
134 | |||
135 | /** |
||
136 | * Formats the given array to be in the format of a leaf. |
||
137 | * A leaf that is an array is an associative array with boolean, string or numeric values. |
||
138 | * The input format is a non associative array of associative array. |
||
139 | * Each associative array must contain: |
||
140 | * a string value for the key LOCALE_KEY which is the locale in the formatted array |
||
141 | * and a boolean, string or numeric value for the key VALUE_KEY which is the value in the formatted array. |
||
142 | * |
||
143 | * The value that cannot be matched in this format are dropped |
||
144 | * |
||
145 | * @param array $leafArray |
||
146 | * |
||
147 | * @return array |
||
148 | */ |
||
149 | 2 | private function formatLeafArray(array $leafArray) |
|
171 | } |
||
172 |