1 | <?php |
||
20 | class MultiLang |
||
21 | { |
||
22 | /** |
||
23 | * Language/Locale. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $lang; |
||
28 | |||
29 | /** |
||
30 | * System environment |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $environment; |
||
35 | |||
36 | /** |
||
37 | * Config. |
||
38 | * |
||
39 | * @var \Longman\LaravelMultiLang\Config |
||
40 | */ |
||
41 | protected $config; |
||
42 | |||
43 | /** |
||
44 | * Repository |
||
45 | * |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $repository; |
||
49 | |||
50 | /** |
||
51 | * Texts. |
||
52 | * |
||
53 | * @var array |
||
54 | */ |
||
55 | protected $texts; |
||
56 | |||
57 | /** |
||
58 | * Missing texts. |
||
59 | * |
||
60 | * @var array |
||
61 | */ |
||
62 | protected $new_texts; |
||
63 | |||
64 | /** |
||
65 | * Create a new MultiLang instance. |
||
66 | * |
||
67 | * @param string $environment |
||
68 | * @param array $config |
||
69 | * @param \Illuminate\Cache\CacheManager $cache |
||
70 | * @param \Illuminate\Database\DatabaseManager $db |
||
71 | */ |
||
72 | 23 | public function __construct($environment, array $config, Cache $cache, Database $db) |
|
82 | |||
83 | 23 | public function setConfig(array $config) |
|
88 | |||
89 | 23 | public function setRepository(Repository $repository) |
|
94 | |||
95 | 2 | public function getRepository() |
|
99 | |||
100 | /** |
||
101 | * Set locale and load texts |
||
102 | * |
||
103 | * @param string $lang |
||
104 | * @param array $texts |
||
105 | * @return void |
||
106 | */ |
||
107 | 21 | public function setLocale($lang, array $texts = null) |
|
120 | |||
121 | /** |
||
122 | * Load texts |
||
123 | * |
||
124 | * @param string $lang |
||
125 | * @return array |
||
126 | */ |
||
127 | 17 | public function loadTexts($lang) |
|
143 | |||
144 | /** |
||
145 | * Get translated text |
||
146 | * |
||
147 | * @param string $key |
||
148 | * @return string |
||
149 | */ |
||
150 | 8 | public function get($key) |
|
170 | |||
171 | /** |
||
172 | * Get texts |
||
173 | * |
||
174 | * @return array |
||
175 | */ |
||
176 | 4 | public function getRedirectUrl(Request $request) |
|
205 | |||
206 | 1 | public function detectLocale(Request $request) |
|
217 | |||
218 | /** |
||
219 | * Get texts |
||
220 | * |
||
221 | * @return array |
||
222 | */ |
||
223 | 4 | public function getTexts() |
|
228 | |||
229 | /** |
||
230 | * Set texts manually |
||
231 | * |
||
232 | * @param array $texts_array |
||
233 | * @return \Longman\LaravelMultiLang\MultiLang |
||
234 | */ |
||
235 | 3 | public function setTexts(array $texts_array) |
|
246 | |||
247 | /** |
||
248 | * Queue missing texts |
||
249 | * |
||
250 | * @param string $key |
||
251 | * @return void |
||
252 | */ |
||
253 | 4 | protected function queueToSave($key) |
|
257 | |||
258 | 2 | public function getUrl($path) |
|
266 | |||
267 | 5 | public function autoSaveIsAllowed() |
|
274 | |||
275 | 18 | public function getLocale() |
|
279 | |||
280 | 1 | public function getLocales() |
|
284 | |||
285 | 3 | public function saveTexts() |
|
294 | } |
||
295 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: