@@ -19,7 +19,7 @@ |
||
19 | 19 | protected function parseFile(string $filename): array |
20 | 20 | { |
21 | 21 | $result = parse_ini_file($filename, true); |
22 | - if ($result === false) { |
|
22 | + if($result === false) { |
|
23 | 23 | throw new \RuntimeException("File $filename does not exist or cannot be read."); |
24 | 24 | } |
25 | 25 | return $result; |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function setLang(string $lang): void |
70 | 70 | { |
71 | - if (is_a($this->resolver, SettableLocaleResolver::class)) { |
|
71 | + if(is_a($this->resolver, SettableLocaleResolver::class)) { |
|
72 | 72 | $oldLang = $this->lang; |
73 | 73 | $this->resolver->setLang($lang); |
74 | 74 | $this->onLanguageChange($this, $oldLang, $lang); |
@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public function setFolders(array $folders): void |
109 | 109 | { |
110 | - foreach ($folders as $folder) { |
|
111 | - if (!is_dir($folder)) { |
|
110 | + foreach($folders as $folder) { |
|
111 | + if(!is_dir($folder)) { |
|
112 | 112 | throw new InvalidFolderException("Folder $folder does not exist."); |
113 | 113 | } |
114 | 114 | $this->folders[] = $folder; |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | |
119 | 119 | protected function addResource(string $filename, string $domain): void |
120 | 120 | { |
121 | - if (!isset($this->resources[$domain]) || !in_array($filename, $this->resources[$domain], true)) { |
|
121 | + if(!isset($this->resources[$domain]) || !in_array($filename, $this->resources[$domain], true)) { |
|
122 | 122 | $this->resources[$domain][] = $filename; |
123 | 123 | } |
124 | 124 | } |
@@ -145,20 +145,20 @@ discard block |
||
145 | 145 | $defaultLang = $this->defaultLang; |
146 | 146 | $defaultFilename = $this->getLanguageFilenameMask(); |
147 | 147 | $defaultFilename = str_replace( |
148 | - [static::DOMAIN_MASK, static::LANGUAGE_MASK,], |
|
149 | - [$name, $defaultLang,], |
|
148 | + [static::DOMAIN_MASK, static::LANGUAGE_MASK, ], |
|
149 | + [$name, $defaultLang, ], |
|
150 | 150 | $defaultFilename |
151 | 151 | ); |
152 | 152 | $files = Finder::findFiles($defaultFilename) |
153 | 153 | ->from(...$this->folders); |
154 | 154 | /** @var \SplFileInfo $file */ |
155 | - foreach ($files as $file) { |
|
155 | + foreach($files as $file) { |
|
156 | 156 | $default = $this->parseFile($file->getPathname()); |
157 | 157 | $this->addResource($file->getPathname(), $name); |
158 | 158 | $lang = []; |
159 | 159 | $filename = str_replace($defaultLang, $this->lang, $defaultFilename); |
160 | 160 | $filename = str_replace($defaultFilename, $filename, $file->getPathname()); |
161 | - if ($this->lang !== $defaultLang && is_file($filename)) { |
|
161 | + if($this->lang !== $defaultLang && is_file($filename)) { |
|
162 | 162 | $lang = $this->parseFile($filename); |
163 | 163 | $this->addResource($filename, $name); |
164 | 164 | } |
@@ -174,20 +174,20 @@ discard block |
||
174 | 174 | */ |
175 | 175 | protected function loadTexts(): void |
176 | 176 | { |
177 | - if ($this->lang === $this->loadedLang) { |
|
177 | + if($this->lang === $this->loadedLang) { |
|
178 | 178 | return; |
179 | 179 | } |
180 | - if (count($this->folders) === 0) { |
|
180 | + if(count($this->folders) === 0) { |
|
181 | 181 | throw new FolderNotSetException("Folder for translations was not set."); |
182 | 182 | } |
183 | 183 | $default = $this->defaultLang; |
184 | 184 | $this->resources = $texts = []; |
185 | 185 | $mask = $this->getLanguageFilenameMask(); |
186 | - $mask = str_replace([static::DOMAIN_MASK, static::LANGUAGE_MASK,], ["*", $default,], $mask); |
|
186 | + $mask = str_replace([static::DOMAIN_MASK, static::LANGUAGE_MASK, ], ["*", $default, ], $mask); |
|
187 | 187 | $files = Finder::findFiles($mask) |
188 | 188 | ->from(...$this->folders); |
189 | 189 | /** @var \SplFileInfo $file */ |
190 | - foreach ($files as $file) { |
|
190 | + foreach($files as $file) { |
|
191 | 191 | $domain = $file->getBasename((string) Strings::after($mask, "*")); |
192 | 192 | $texts[$domain] = $this->loadDomain($domain); |
193 | 193 | } |
@@ -222,20 +222,20 @@ discard block |
||
222 | 222 | */ |
223 | 223 | public function getAvailableLanguages(): array |
224 | 224 | { |
225 | - if (count($this->folders) === 0) { |
|
225 | + if(count($this->folders) === 0) { |
|
226 | 226 | throw new FolderNotSetException("Folder for translations was not set."); |
227 | 227 | } |
228 | 228 | $languages = []; |
229 | 229 | $extension = $this->extension; |
230 | 230 | $mask = $this->getLanguageFilenameMask(); |
231 | - $mask = str_replace([static::DOMAIN_MASK, static::LANGUAGE_MASK,], "*", $mask); |
|
231 | + $mask = str_replace([static::DOMAIN_MASK, static::LANGUAGE_MASK, ], "*", $mask); |
|
232 | 232 | $files = Finder::findFiles($mask) |
233 | 233 | ->from(...$this->folders); |
234 | 234 | /** @var \SplFileInfo $file */ |
235 | - foreach ($files as $file) { |
|
235 | + foreach($files as $file) { |
|
236 | 236 | $filename = $file->getBasename(".$extension"); |
237 | 237 | $lang = (string) Strings::after($filename, "."); |
238 | - if (!in_array($lang, $languages, true)) { |
|
238 | + if(!in_array($lang, $languages, true)) { |
|
239 | 239 | $languages[] = $lang; |
240 | 240 | } |
241 | 241 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | |
29 | 29 | protected function loadTexts(): void |
30 | 30 | { |
31 | - if (count($this->folders) === 0) { |
|
31 | + if(count($this->folders) === 0) { |
|
32 | 32 | throw new FolderNotSetException("Folder for translations was not set."); |
33 | 33 | } |
34 | 34 | $this->resources = $texts = []; |
@@ -36,15 +36,15 @@ discard block |
||
36 | 36 | $files = Finder::findFiles($filename) |
37 | 37 | ->from(...$this->folders); |
38 | 38 | /** @var \SplFileInfo $file */ |
39 | - foreach ($files as $file) { |
|
39 | + foreach($files as $file) { |
|
40 | 40 | $texts = array_merge($texts, $this->parseFile($file->getPathname())); |
41 | - if (isset($texts["__resources"])) { |
|
41 | + if(isset($texts["__resources"])) { |
|
42 | 42 | $this->resources = array_merge($this->resources, $texts["__resources"]); |
43 | 43 | unset($texts["__resources"]); |
44 | 44 | } else { |
45 | 45 | /** @var string[] $domains */ |
46 | 46 | $domains = array_keys($texts); |
47 | - foreach ($domains as $domain) { |
|
47 | + foreach($domains as $domain) { |
|
48 | 48 | $this->addResource($file->getPathname(), $domain); |
49 | 49 | } |
50 | 50 | } |
@@ -22,7 +22,7 @@ |
||
22 | 22 | protected function parseFile(string $filename): array |
23 | 23 | { |
24 | 24 | $content = file_get_contents($filename); |
25 | - if ($content === false) { |
|
25 | + if($content === false) { |
|
26 | 26 | throw new \RuntimeException("File $filename does not exist or cannot be read."); |
27 | 27 | } |
28 | 28 | return Json::decode($content, Json::FORCE_ARRAY); |
@@ -21,7 +21,7 @@ |
||
21 | 21 | protected function parseFile(string $filename): array |
22 | 22 | { |
23 | 23 | $content = file_get_contents($filename); |
24 | - if ($content === false) { |
|
24 | + if($content === false) { |
|
25 | 25 | throw new \RuntimeException("File $filename does not exist or cannot be read."); |
26 | 26 | } |
27 | 27 | return Neon::decode($content); |
@@ -3,11 +3,11 @@ |
||
3 | 3 | |
4 | 4 | namespace Nexendrie\Translation\Bridges\NetteDI; |
5 | 5 | |
6 | -if (false) { // @phpstan-ignore if.alwaysFalse |
|
6 | +if(false) { // @phpstan-ignore if.alwaysFalse |
|
7 | 7 | /** @deprecated Use TranslationProvider */ |
8 | 8 | interface ITranslationProvider extends TranslationProvider |
9 | 9 | { |
10 | 10 | } |
11 | -} elseif (!interface_exists(ITranslationProvider::class)) { |
|
11 | +} elseif(!interface_exists(ITranslationProvider::class)) { |
|
12 | 12 | class_alias(TranslationProvider::class, ITranslationProvider::class); |
13 | 13 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | "localeResolver" => Expect::anyOf( |
89 | 89 | Expect::string(), |
90 | 90 | Expect::arrayOf("string") |
91 | - )->default(["param", "session", "header",]), |
|
91 | + )->default(["param", "session", "header", ]), |
|
92 | 92 | "default" => Expect::string("en"), |
93 | 93 | "debugger" => Expect::bool(Helpers::expand("%debugMode%", $params)), |
94 | 94 | "loader" => Expect::structure([ |
@@ -115,14 +115,14 @@ discard block |
||
115 | 115 | $config = $this->getConfig(); |
116 | 116 | $return = []; |
117 | 117 | $resolvers = $config->localeResolver; |
118 | - if (!is_array($resolvers)) { |
|
118 | + if(!is_array($resolvers)) { |
|
119 | 119 | $resolvers = [$resolvers]; |
120 | 120 | } |
121 | - foreach ($resolvers as $resolverName) { |
|
121 | + foreach($resolvers as $resolverName) { |
|
122 | 122 | $resolver = Arrays::get($this->resolvers, strtolower($resolverName), ""); |
123 | - if ($resolver !== "") { |
|
123 | + if($resolver !== "") { |
|
124 | 124 | $return[] = $resolver; |
125 | - } elseif (class_exists($resolverName) && is_subclass_of($resolverName, LocaleResolver::class)) { |
|
125 | + } elseif(class_exists($resolverName) && is_subclass_of($resolverName, LocaleResolver::class)) { |
|
126 | 126 | $return[] = $resolverName; |
127 | 127 | } else { |
128 | 128 | throw new InvalidLocaleResolverException("Invalid locale resolver $resolverName."); |
@@ -140,9 +140,9 @@ discard block |
||
140 | 140 | /** @var string $loaderName */ |
141 | 141 | $loaderName = $config->loader["name"]; |
142 | 142 | $loader = Arrays::get($this->loaders, strtolower($loaderName), ""); |
143 | - if ($loader !== "") { |
|
143 | + if($loader !== "") { |
|
144 | 144 | return $loader; |
145 | - } elseif (class_exists($loaderName) && is_subclass_of($loaderName, Loader::class)) { |
|
145 | + } elseif(class_exists($loaderName) && is_subclass_of($loaderName, Loader::class)) { |
|
146 | 146 | return $loaderName; |
147 | 147 | } |
148 | 148 | throw new InvalidLoaderException("Invalid translation loader $loaderName."); |
@@ -157,11 +157,11 @@ discard block |
||
157 | 157 | $config = $this->getConfig(); |
158 | 158 | $folders = $config->loader["folders"]; |
159 | 159 | /** @var TranslationProvider $extension */ |
160 | - foreach ($this->compiler->getExtensions(TranslationProvider::class) as $extension) { |
|
160 | + foreach($this->compiler->getExtensions(TranslationProvider::class) as $extension) { |
|
161 | 161 | $folders = array_merge($folders, array_values($extension->getTranslationResources())); |
162 | 162 | } |
163 | - foreach ($folders as $folder) { |
|
164 | - if (!is_dir($folder)) { |
|
163 | + foreach($folders as $folder) { |
|
164 | + if(!is_dir($folder)) { |
|
165 | 165 | throw new InvalidFolderException("Folder $folder does not exist."); |
166 | 166 | } |
167 | 167 | } |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | $config = $this->getConfig(); |
177 | 177 | /** @var string $messageSelector */ |
178 | 178 | $messageSelector = $config->messageSelector; |
179 | - if (class_exists($messageSelector) && is_subclass_of($messageSelector, IMessageSelector::class)) { |
|
179 | + if(class_exists($messageSelector) && is_subclass_of($messageSelector, IMessageSelector::class)) { |
|
180 | 180 | return $messageSelector; |
181 | 181 | } |
182 | 182 | throw new InvalidMessageSelectorException("Invalid message selector $messageSelector."); |
@@ -201,20 +201,20 @@ discard block |
||
201 | 201 | $messageSelector = $this->resolveMessageSelector(); |
202 | 202 | $builder->addDefinition($this->prefix(self::SERVICE_MESSAGE_SELECTOR)) |
203 | 203 | ->setType($messageSelector); |
204 | - if (count($resolvers) === 1) { |
|
204 | + if(count($resolvers) === 1) { |
|
205 | 205 | $builder->addDefinition($this->prefix(self::SERVICE_LOCALE_RESOLVER)) |
206 | 206 | ->setType($resolvers[0]); |
207 | 207 | } else { |
208 | 208 | $chainResolver = $builder->addDefinition($this->prefix(self::SERVICE_LOCALE_RESOLVER)) |
209 | 209 | ->setType(ChainLocaleResolver::class); |
210 | - foreach ($resolvers as $index => $resolver) { |
|
210 | + foreach($resolvers as $index => $resolver) { |
|
211 | 211 | $resolverService = $builder->addDefinition($this->prefix("resolver.$index")) |
212 | 212 | ->setType($resolver) |
213 | 213 | ->setAutowired(false); |
214 | 214 | $chainResolver->addSetup('$service[] = ?', [$resolverService]); |
215 | 215 | } |
216 | 216 | } |
217 | - if ($config->debugger && interface_exists(\Tracy\IBarPanel::class)) { |
|
217 | + if($config->debugger && interface_exists(\Tracy\IBarPanel::class)) { |
|
218 | 218 | $builder->addDefinition($this->prefix(self::SERVICE_PANEL)) |
219 | 219 | ->setType(TranslationPanel::class); |
220 | 220 | /** @var ServiceDefinition $tracy */ |
@@ -232,24 +232,24 @@ discard block |
||
232 | 232 | $config = $this->getConfig(); |
233 | 233 | /** @var ServiceDefinition $loader */ |
234 | 234 | $loader = $builder->getDefinition($this->prefix(self::SERVICE_LOADER)); |
235 | - if (in_array(FileLoader::class, (array) class_implements((string) $loader->class), true)) { |
|
235 | + if(in_array(FileLoader::class, (array) class_implements((string) $loader->class), true)) { |
|
236 | 236 | $folders = $this->getFolders(); |
237 | 237 | $loader->addSetup("setFolders", [$folders]); |
238 | - foreach ($folders as $folder) { |
|
238 | + foreach($folders as $folder) { |
|
239 | 239 | $builder->addDependency($folder); |
240 | 240 | } |
241 | 241 | } |
242 | 242 | /** @var ServiceDefinition $resolver */ |
243 | 243 | $resolver = $builder->getDefinition($this->prefix(self::SERVICE_LOCALE_RESOLVER)); |
244 | - if (in_array(AppRequestAwareLocaleResolver::class, (array) class_implements((string) $resolver->class), true)) { |
|
244 | + if(in_array(AppRequestAwareLocaleResolver::class, (array) class_implements((string) $resolver->class), true)) { |
|
245 | 245 | $applicationService = $builder->getByType(Application::class) ?? "application"; |
246 | - if ($builder->hasDefinition($applicationService)) { |
|
246 | + if($builder->hasDefinition($applicationService)) { |
|
247 | 247 | /** @var ServiceDefinition $application */ |
248 | 248 | $application = $builder->getDefinition($applicationService); |
249 | 249 | $application->addSetup('$service->onRequest[] = ?', [[$resolver, "onRequest"]]); |
250 | 250 | } |
251 | 251 | } |
252 | - if ($config->compiler["enabled"]) { |
|
252 | + if($config->compiler["enabled"]) { |
|
253 | 253 | $serviceName = $this->prefix(self::SERVICE_LOADER); |
254 | 254 | /** @var ServiceDefinition $loader */ |
255 | 255 | $loader = $builder->getDefinition($serviceName); |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | ->setFactory(CatalogueCompiler::class, [$loader, $folder, $config->compiler["languages"]]); |
266 | 266 | } |
267 | 267 | $latteFactoryService = $builder->getByType(LatteFactory::class) ?? "latte.latteFactory"; |
268 | - if ($builder->hasDefinition($latteFactoryService)) { |
|
268 | + if($builder->hasDefinition($latteFactoryService)) { |
|
269 | 269 | /** @var FactoryDefinition $latteFactory */ |
270 | 270 | $latteFactory = $builder->getDefinition($latteFactoryService); |
271 | 271 | $latteFactory->getResultDefinition()->addSetup( |
@@ -284,10 +284,10 @@ discard block |
||
284 | 284 | $config = $this->getConfig(); |
285 | 285 | $initialize = $this->initialization; |
286 | 286 | $initialize->addBody('$translator = $this->getService(?);', [$this->prefix(self::SERVICE_TRANSLATOR)]); |
287 | - foreach ($config->onUntranslated as &$task) { |
|
288 | - if (!is_array($task)) { |
|
287 | + foreach($config->onUntranslated as &$task) { |
|
288 | + if(!is_array($task)) { |
|
289 | 289 | $task = explode("::", $task); |
290 | - } elseif (str_starts_with($task[0], "@")) { |
|
290 | + } elseif(str_starts_with($task[0], "@")) { |
|
291 | 291 | $initialize->addBody( |
292 | 292 | '$translator->onUntranslated[] = [$this->getService(?), ?];', |
293 | 293 | [substr($task[0], 1), $task[1]] |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | foreach($resolvers as $resolver) { |
301 | 301 | $this->getService($resolver)->setLoader($this->getService(?)); |
302 | 302 | }', [LoaderAwareLocaleResolver::class, $this->prefix(self::SERVICE_LOADER)]); |
303 | - if ($config->compiler["enabled"]) { |
|
303 | + if($config->compiler["enabled"]) { |
|
304 | 304 | $initialize->addBody('$this->getService(?)->compile();', [$this->prefix(self::SERVICE_CATALOGUE_COMPILER)]); |
305 | 305 | } |
306 | 306 | } |
@@ -38,7 +38,7 @@ |
||
38 | 38 | |
39 | 39 | protected function renderLink(string $resource): string |
40 | 40 | { |
41 | - if (is_file($resource)) { |
|
41 | + if(is_file($resource)) { |
|
42 | 42 | return \Tracy\Helpers::editorLink($resource); |
43 | 43 | } |
44 | 44 | return $resource; |
@@ -3,11 +3,11 @@ |
||
3 | 3 | |
4 | 4 | namespace Nexendrie\Translation\Bridges\NetteApplication; |
5 | 5 | |
6 | -if (false) { // @phpstan-ignore if.alwaysFalse |
|
6 | +if(false) { // @phpstan-ignore if.alwaysFalse |
|
7 | 7 | /** @deprecated Use AppRequestAwareLocaleResolver */ |
8 | 8 | interface IAppRequestAwareLocaleResolver extends AppRequestAwareLocaleResolver |
9 | 9 | { |
10 | 10 | } |
11 | -} elseif (!interface_exists(IAppRequestAwareLocaleResolver::class)) { |
|
11 | +} elseif(!interface_exists(IAppRequestAwareLocaleResolver::class)) { |
|
12 | 12 | class_alias(AppRequestAwareLocaleResolver::class, IAppRequestAwareLocaleResolver::class); |
13 | 13 | } |