1 | <?php |
||
19 | class Lang |
||
20 | { |
||
21 | /** |
||
22 | * The array holding the strings |
||
23 | * |
||
24 | * @var string[] |
||
25 | */ |
||
26 | protected $_lang = array(); |
||
27 | |||
28 | /** |
||
29 | * Loads the language xml file. |
||
30 | * |
||
31 | * @param string $path |
||
32 | * |
||
33 | * @throws \Exception if it cannot find the XML file. |
||
34 | * @throws ImportException if the XML file has got a corrupted structure. |
||
35 | */ |
||
36 | 3 | public function loadLang($path) |
|
62 | |||
63 | /** |
||
64 | * This is used to detect the Client's browser language. |
||
65 | * |
||
66 | * @return string[] the shortened string of the browser's language. |
||
67 | */ |
||
68 | 3 | protected function detectBrowserLanguage() |
|
99 | |||
100 | /** |
||
101 | * Finds out if the language we are looking for exists or not. |
||
102 | * |
||
103 | * @param string $path The path to look for the language file |
||
104 | * @param string[] $language The name of the language |
||
105 | * |
||
106 | * @return bool |
||
107 | */ |
||
108 | 4 | protected function findLanguage($path, $language) |
|
133 | |||
134 | /** |
||
135 | * Adds a new variable to lang. |
||
136 | * |
||
137 | * @param string $key Name of the variable |
||
138 | * @param string $value Value of the variable |
||
139 | * |
||
140 | * @throws \Exception |
||
141 | * @return boolean|null |
||
142 | */ |
||
143 | 5 | protected function set($key, $value) |
|
162 | |||
163 | /** |
||
164 | * Tests if given $key exists in lang |
||
165 | * |
||
166 | * @param string $key |
||
167 | * |
||
168 | * @return bool |
||
169 | */ |
||
170 | 4 | public function has($key) |
|
174 | |||
175 | /** |
||
176 | * Getter |
||
177 | * |
||
178 | * @param string|int $key |
||
179 | * |
||
180 | * @return string|int|bool|null|object |
||
181 | */ |
||
182 | 1 | public function __get($key) |
|
186 | |||
187 | /** |
||
188 | * Returns the value of the specified $key in lang. |
||
189 | * |
||
190 | * @param string|mixed[] $key Name of the variable |
||
191 | * |
||
192 | * @return string|null Value of the specified $key |
||
193 | */ |
||
194 | 1 | public function get($key) |
|
221 | |||
222 | /** |
||
223 | * Tests if the key is set. |
||
224 | * |
||
225 | * @param string|int $key |
||
226 | * |
||
227 | * @return bool |
||
228 | */ |
||
229 | public function __isset($key) |
||
233 | |||
234 | /** |
||
235 | * Returns the whole lang as an array. |
||
236 | * |
||
237 | * @return array Whole lang |
||
238 | */ |
||
239 | 1 | public function getAll() |
|
243 | } |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: