1 | <?php |
||
20 | class TransPublisher implements TransPublisherContract |
||
21 | { |
||
22 | /* ----------------------------------------------------------------- |
||
23 | | Properties |
||
24 | | ----------------------------------------------------------------- |
||
25 | */ |
||
26 | |||
27 | /** |
||
28 | * The filesystem instance. |
||
29 | * |
||
30 | * @var \Illuminate\Filesystem\Filesystem |
||
31 | */ |
||
32 | private $filesystem; |
||
33 | |||
34 | /** |
||
35 | * The TransManager instance. |
||
36 | * |
||
37 | * @var \Arcanedev\LaravelLang\Contracts\TransManager |
||
38 | */ |
||
39 | private $manager; |
||
40 | |||
41 | /** |
||
42 | * Available locales. |
||
43 | * |
||
44 | * @var \Arcanedev\LaravelLang\Entities\LocaleCollection |
||
45 | */ |
||
46 | private $locales; |
||
47 | |||
48 | /** |
||
49 | * The application lang path. |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | private $langPath; |
||
54 | |||
55 | /** |
||
56 | * Publish's results. |
||
57 | * |
||
58 | * @var array |
||
59 | */ |
||
60 | private $results = []; |
||
61 | |||
62 | /* ----------------------------------------------------------------- |
||
63 | | Constructor |
||
64 | | ----------------------------------------------------------------- |
||
65 | */ |
||
66 | |||
67 | /** |
||
68 | * Make TransPublisher instance. |
||
69 | * |
||
70 | * @param \Illuminate\Filesystem\Filesystem $filesystem |
||
71 | * @param \Arcanedev\LaravelLang\Contracts\TransManager $manager |
||
72 | * @param string $langPath |
||
73 | */ |
||
74 | 78 | public function __construct(Filesystem $filesystem, TransManagerContract $manager, string $langPath) |
|
82 | |||
83 | /** |
||
84 | * Start the engine. |
||
85 | */ |
||
86 | 78 | private function init(): void |
|
90 | |||
91 | /* ----------------------------------------------------------------- |
||
92 | | Getters & Setters |
||
93 | | ----------------------------------------------------------------- |
||
94 | */ |
||
95 | |||
96 | /** |
||
97 | * Get the locale destination path. |
||
98 | * |
||
99 | * @param string $locale |
||
100 | * |
||
101 | * @return string |
||
102 | */ |
||
103 | 42 | private function getDestinationPath(string $locale): string |
|
107 | |||
108 | /** |
||
109 | * Get a locale from the collection. |
||
110 | * |
||
111 | * @param string $key |
||
112 | * @param mixed $default |
||
113 | * |
||
114 | * @return \Arcanedev\LaravelLang\Entities\Locale|mixed |
||
115 | */ |
||
116 | 42 | private function getLocale(string $key, $default = null) |
|
120 | |||
121 | /* ----------------------------------------------------------------- |
||
122 | | Main Methods |
||
123 | | ----------------------------------------------------------------- |
||
124 | */ |
||
125 | |||
126 | /** |
||
127 | * Publish a lang. |
||
128 | * |
||
129 | * @param string $locale |
||
130 | * @param array $options |
||
131 | * |
||
132 | * @return array |
||
133 | */ |
||
134 | 54 | public function publish(string $locale, array $options = []): array |
|
159 | |||
160 | /* ----------------------------------------------------------------- |
||
161 | | Check Methods |
||
162 | | ----------------------------------------------------------------- |
||
163 | */ |
||
164 | |||
165 | /** |
||
166 | * Check if the locale is a default one (English is shipped with laravel). |
||
167 | * |
||
168 | * @param string $locale |
||
169 | * |
||
170 | * @return bool |
||
171 | */ |
||
172 | 60 | public function isDefault(string $locale): bool |
|
176 | |||
177 | /** |
||
178 | * Check if the locale is supported. |
||
179 | * |
||
180 | * @param string $key |
||
181 | * |
||
182 | * @return bool |
||
183 | */ |
||
184 | 48 | public function isSupported(string $key): bool |
|
188 | |||
189 | /** |
||
190 | * Check if the locale is supported or fail. |
||
191 | * |
||
192 | * @param string $locale |
||
193 | * |
||
194 | * @throws \Arcanedev\LaravelLang\Exceptions\LangPublishException |
||
195 | */ |
||
196 | 48 | private function checkLocale(string $locale): void |
|
202 | |||
203 | /* ----------------------------------------------------------------- |
||
204 | | Other Methods |
||
205 | | ----------------------------------------------------------------- |
||
206 | */ |
||
207 | |||
208 | /** |
||
209 | * Publish the translation file. |
||
210 | * |
||
211 | * @param SplFileInfo $file |
||
212 | * @param string $locale |
||
213 | * @param string $destination |
||
214 | * @param array $options |
||
215 | */ |
||
216 | 42 | private function publishFile(SplFileInfo $file, string $locale, string $destination, array $options): void |
|
239 | |||
240 | /** |
||
241 | * Reset the publish results. |
||
242 | */ |
||
243 | 54 | private function resetResults(): void |
|
250 | |||
251 | /** |
||
252 | * Check if the given key exists in results. |
||
253 | * |
||
254 | * @param string $key |
||
255 | * |
||
256 | * @return bool |
||
257 | */ |
||
258 | 42 | private function isInResults(string $key): bool |
|
263 | } |
||
264 |