1 | <?php |
||
19 | class TransPublisher implements TransPublisherContract |
||
20 | { |
||
21 | /* ----------------------------------------------------------------- |
||
22 | | Properties |
||
23 | | ----------------------------------------------------------------- |
||
24 | */ |
||
25 | |||
26 | /** |
||
27 | * The filesystem instance. |
||
28 | * |
||
29 | * @var \Illuminate\Filesystem\Filesystem |
||
30 | */ |
||
31 | private $filesystem; |
||
32 | |||
33 | /** |
||
34 | * The TransManager instance. |
||
35 | * |
||
36 | * @var \Arcanedev\LaravelLang\Contracts\TransManager |
||
37 | */ |
||
38 | private $manager; |
||
39 | |||
40 | /** |
||
41 | * Available locales. |
||
42 | * |
||
43 | * @var \Arcanedev\LaravelLang\Entities\LocaleCollection |
||
44 | */ |
||
45 | private $locales; |
||
46 | |||
47 | /** |
||
48 | * The application lang path. |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | private $langPath; |
||
53 | |||
54 | /** |
||
55 | * Publish's results. |
||
56 | * |
||
57 | * @var array |
||
58 | */ |
||
59 | private $results = []; |
||
60 | |||
61 | /* ----------------------------------------------------------------- |
||
62 | | Constructor |
||
63 | | ----------------------------------------------------------------- |
||
64 | */ |
||
65 | |||
66 | /** |
||
67 | * Make TransPublisher instance. |
||
68 | * |
||
69 | * @param \Illuminate\Filesystem\Filesystem $filesystem |
||
70 | * @param \Arcanedev\LaravelLang\Contracts\TransManager $manager |
||
71 | * @param string $langPath |
||
72 | */ |
||
73 | 84 | public function __construct(Filesystem $filesystem, TransManagerContract $manager, string $langPath) |
|
81 | |||
82 | /** |
||
83 | * Start the engine. |
||
84 | */ |
||
85 | 84 | private function init(): void |
|
89 | |||
90 | /* ----------------------------------------------------------------- |
||
91 | | Getters & Setters |
||
92 | | ----------------------------------------------------------------- |
||
93 | */ |
||
94 | |||
95 | /** |
||
96 | * Get the locale destination path. |
||
97 | * |
||
98 | * @param string $locale |
||
99 | * |
||
100 | * @return string |
||
101 | */ |
||
102 | 48 | private function getDestinationPath(string $locale): string |
|
106 | |||
107 | /** |
||
108 | * Get a locale from the collection. |
||
109 | * |
||
110 | * @param string $key |
||
111 | * @param mixed $default |
||
112 | * |
||
113 | * @return \Arcanedev\LaravelLang\Entities\Locale|mixed |
||
114 | */ |
||
115 | 48 | private function getLocale(string $key, $default = null) |
|
119 | |||
120 | /* ----------------------------------------------------------------- |
||
121 | | Main Methods |
||
122 | | ----------------------------------------------------------------- |
||
123 | */ |
||
124 | |||
125 | /** |
||
126 | * Publish a lang. |
||
127 | * |
||
128 | * @param string $locale |
||
129 | * @param array $options |
||
130 | * |
||
131 | * @return array |
||
132 | */ |
||
133 | 60 | public function publish(string $locale, array $options = []): array |
|
164 | |||
165 | /** |
||
166 | * Publish the json file. |
||
167 | * |
||
168 | * @param string $locale |
||
169 | * @param string $destination |
||
170 | * @param array $options |
||
171 | * |
||
172 | * @return bool |
||
173 | */ |
||
174 | 6 | private function publishJson(string $locale, string $destination, array $options = []): bool |
|
195 | |||
196 | /* ----------------------------------------------------------------- |
||
197 | | Check Methods |
||
198 | | ----------------------------------------------------------------- |
||
199 | */ |
||
200 | |||
201 | /** |
||
202 | * Check if the locale is a default one (English is shipped with laravel). |
||
203 | * |
||
204 | * @param string $locale |
||
205 | * |
||
206 | * @return bool |
||
207 | */ |
||
208 | 66 | public function isDefault(string $locale): bool |
|
212 | |||
213 | /** |
||
214 | * Check if the locale is supported. |
||
215 | * |
||
216 | * @param string $key |
||
217 | * |
||
218 | * @return bool |
||
219 | */ |
||
220 | 54 | public function isSupported(string $key): bool |
|
224 | |||
225 | /** |
||
226 | * Check if the locale is supported or fail. |
||
227 | * |
||
228 | * @param string $locale |
||
229 | * |
||
230 | * @throws \Arcanedev\LaravelLang\Exceptions\LangPublishException |
||
231 | */ |
||
232 | 54 | private function checkLocale(string $locale): void |
|
238 | |||
239 | /* ----------------------------------------------------------------- |
||
240 | | Other Methods |
||
241 | | ----------------------------------------------------------------- |
||
242 | */ |
||
243 | |||
244 | /** |
||
245 | * Publish the translation file. |
||
246 | * |
||
247 | * @param SplFileInfo $file |
||
248 | * @param string $locale |
||
249 | * @param string $destination |
||
250 | * @param array $options |
||
251 | */ |
||
252 | 48 | private function publishFile(SplFileInfo $file, string $locale, string $destination, array $options): void |
|
275 | |||
276 | /** |
||
277 | * Reset the publish results. |
||
278 | */ |
||
279 | 60 | private function resetResults(): void |
|
286 | |||
287 | /** |
||
288 | * Check if the given key exists in results. |
||
289 | * |
||
290 | * @param string $key |
||
291 | * |
||
292 | * @return bool |
||
293 | */ |
||
294 | 48 | private function isInResults(string $key): bool |
|
299 | } |
||
300 |