@@ -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 | } |
@@ -46,8 +46,7 @@ |
||
46 | 46 | * @author Jakub Konečný |
47 | 47 | * @method \stdClass getConfig() |
48 | 48 | */ |
49 | -final class TranslationExtension extends CompilerExtension |
|
50 | -{ |
|
49 | +final class TranslationExtension extends CompilerExtension { |
|
51 | 50 | /** @internal */ |
52 | 51 | public const SERVICE_TRANSLATOR = "translator"; |
53 | 52 | /** @internal */ |
@@ -162,7 +162,7 @@ |
||
162 | 162 | } |
163 | 163 | foreach ($folders as $folder) { |
164 | 164 | if (!is_dir($folder)) { |
165 | - throw new InvalidFolderException("Folder $folder does not exist."); |
|
165 | + throw new InvalidFolderException("folder $folder does not exist."); |
|
166 | 166 | } |
167 | 167 | } |
168 | 168 | return $folders; |
@@ -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; |
@@ -12,10 +12,8 @@ |
||
12 | 12 | * |
13 | 13 | * @author Jakub Konečný |
14 | 14 | */ |
15 | -final class TranslationPanel implements IBarPanel |
|
16 | -{ |
|
17 | - public function __construct(private readonly Translator $translator, private readonly Loader $loader) |
|
18 | - { |
|
15 | +final class TranslationPanel implements IBarPanel { |
|
16 | + public function __construct(private readonly Translator $translator, private readonly Loader $loader) { |
|
19 | 17 | } |
20 | 18 | |
21 | 19 | public function getTab(): string |
@@ -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 | } |
@@ -3,10 +3,10 @@ |
||
3 | 3 | |
4 | 4 | namespace Nexendrie\Translation\Bridges\NetteApplication; |
5 | 5 | |
6 | -if (false) { // @phpstan-ignore if.alwaysFalse |
|
6 | +if (false) { |
|
7 | +// @phpstan-ignore if.alwaysFalse |
|
7 | 8 | /** @deprecated Use AppRequestAwareLocaleResolver */ |
8 | - interface IAppRequestAwareLocaleResolver extends AppRequestAwareLocaleResolver |
|
9 | - { |
|
9 | + interface IAppRequestAwareLocaleResolver extends AppRequestAwareLocaleResolver { |
|
10 | 10 | } |
11 | 11 | } elseif (!interface_exists(IAppRequestAwareLocaleResolver::class)) { |
12 | 12 | class_alias(AppRequestAwareLocaleResolver::class, IAppRequestAwareLocaleResolver::class); |
@@ -36,7 +36,7 @@ |
||
36 | 36 | public function onRequest(Application $application, Request $request): void |
37 | 37 | { |
38 | 38 | $locale = $request->getParameter($this->param); |
39 | - if ($request->method === Request::FORWARD && $locale === null) { |
|
39 | + if($request->method === Request::FORWARD && $locale === null) { |
|
40 | 40 | return; |
41 | 41 | } |
42 | 42 | $this->request = $request; |
@@ -11,8 +11,7 @@ |
||
11 | 11 | * |
12 | 12 | * @author Jakub Konečný |
13 | 13 | */ |
14 | -final class ParamLocaleResolver implements AppRequestAwareLocaleResolver |
|
15 | -{ |
|
14 | +final class ParamLocaleResolver implements AppRequestAwareLocaleResolver { |
|
16 | 15 | private ?Request $request = null; |
17 | 16 | /** @var string */ |
18 | 17 | public string $param = "locale"; |
@@ -12,7 +12,6 @@ |
||
12 | 12 | * |
13 | 13 | * @author Jakub Konečný |
14 | 14 | */ |
15 | -interface AppRequestAwareLocaleResolver extends LocaleResolver |
|
16 | -{ |
|
15 | +interface AppRequestAwareLocaleResolver extends LocaleResolver { |
|
17 | 16 | public function onRequest(Application $application, Request $request): void; |
18 | 17 | } |
@@ -8,6 +8,5 @@ |
||
8 | 8 | * |
9 | 9 | * @author Jakub Konečný |
10 | 10 | */ |
11 | -class InvalidMessageSelectorException extends InvalidStateException |
|
12 | -{ |
|
11 | +class InvalidMessageSelectorException extends InvalidStateException { |
|
13 | 12 | } |
@@ -3,6 +3,5 @@ |
||
3 | 3 | |
4 | 4 | namespace Nexendrie\Translation; |
5 | 5 | |
6 | -class FolderNotSetException extends InvalidStateException |
|
7 | -{ |
|
6 | +class FolderNotSetException extends InvalidStateException { |
|
8 | 7 | } |
@@ -3,11 +3,11 @@ |
||
3 | 3 | |
4 | 4 | namespace Nexendrie\Translation; |
5 | 5 | |
6 | -if (false) { // @phpstan-ignore if.alwaysFalse |
|
6 | +if(false) { // @phpstan-ignore if.alwaysFalse |
|
7 | 7 | /** @deprecated Use SettableLocaleResolver */ |
8 | 8 | interface ISettableLocaleResolver extends SettableLocaleResolver |
9 | 9 | { |
10 | 10 | } |
11 | -} elseif (!interface_exists(ISettableLocaleResolver::class)) { |
|
11 | +} elseif(!interface_exists(ISettableLocaleResolver::class)) { |
|
12 | 12 | class_alias(SettableLocaleResolver::class, ISettableLocaleResolver::class); |
13 | 13 | } |
@@ -3,10 +3,10 @@ |
||
3 | 3 | |
4 | 4 | namespace Nexendrie\Translation; |
5 | 5 | |
6 | -if (false) { // @phpstan-ignore if.alwaysFalse |
|
6 | +if (false) { |
|
7 | +// @phpstan-ignore if.alwaysFalse |
|
7 | 8 | /** @deprecated Use SettableLocaleResolver */ |
8 | - interface ISettableLocaleResolver extends SettableLocaleResolver |
|
9 | - { |
|
9 | + interface ISettableLocaleResolver extends SettableLocaleResolver { |
|
10 | 10 | } |
11 | 11 | } elseif (!interface_exists(ISettableLocaleResolver::class)) { |
12 | 12 | class_alias(SettableLocaleResolver::class, ISettableLocaleResolver::class); |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | |
26 | 26 | public function __construct(Session $session = null) |
27 | 27 | { |
28 | - if ($session === null) { |
|
28 | + if($session === null) { |
|
29 | 29 | $request = (new RequestFactory())->fromGlobals(); |
30 | 30 | $response = new Response(); |
31 | 31 | $session = new Session($request, $response); |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | public function getLang(): ?string |
41 | 41 | { |
42 | 42 | $lang = (string) $this->section->{$this->varName}; |
43 | - if ($lang === '') { |
|
43 | + if($lang === '') { |
|
44 | 44 | return null; |
45 | 45 | } |
46 | 46 | return $lang; |
@@ -15,16 +15,14 @@ |
||
15 | 15 | * @author Jakub Konečný |
16 | 16 | * @property string|null $lang |
17 | 17 | */ |
18 | -final class SessionLocaleResolver implements SettableLocaleResolver |
|
19 | -{ |
|
18 | +final class SessionLocaleResolver implements SettableLocaleResolver { |
|
20 | 19 | use \Nette\SmartObject; |
21 | 20 | |
22 | 21 | private readonly Session $session; |
23 | 22 | private readonly SessionSection $section; |
24 | 23 | public string $varName = "lang"; |
25 | 24 | |
26 | - public function __construct(Session $session = null) |
|
27 | - { |
|
25 | + public function __construct(Session $session = null) { |
|
28 | 26 | if ($session === null) { |
29 | 27 | $request = (new RequestFactory())->fromGlobals(); |
30 | 28 | $response = new Response(); |