@@ -28,15 +28,18 @@ discard block |
||
| 28 | 28 | 'namespaces' => $config->getNamespaces(), |
| 29 | 29 | ]); |
| 30 | 30 | |
| 31 | - foreach ($this->config->getDependencies() as $dependency) { |
|
| 31 | + foreach ($this->config->getDependencies() as $dependency) |
|
| 32 | + { |
|
| 32 | 33 | $this->addDependency($dependency->resolve($factory)); |
| 33 | 34 | } |
| 34 | 35 | |
| 35 | - foreach ($this->config->getEngines() as $engine) { |
|
| 36 | + foreach ($this->config->getEngines() as $engine) |
|
| 37 | + { |
|
| 36 | 38 | $this->addEngine($engine->resolve($factory)); |
| 37 | 39 | } |
| 38 | 40 | |
| 39 | - if ($this->config->isCacheEnabled()) { |
|
| 41 | + if ($this->config->isCacheEnabled()) |
|
| 42 | + { |
|
| 40 | 43 | $this->cache = new ViewCache(); |
| 41 | 44 | } |
| 42 | 45 | } |
@@ -93,7 +96,8 @@ discard block |
||
| 93 | 96 | |
| 94 | 97 | // Rotate all possible context variants and warm up cache |
| 95 | 98 | $generator = new ContextGenerator($this->context); |
| 96 | - foreach ($generator->generate() as $context) { |
|
| 99 | + foreach ($generator->generate() as $context) |
|
| 100 | + { |
|
| 97 | 101 | $engine->reset($path, $context); |
| 98 | 102 | $engine->compile($path, $context); |
| 99 | 103 | } |
@@ -110,7 +114,8 @@ discard block |
||
| 110 | 114 | |
| 111 | 115 | // Rotate all possible context variants and warm up cache |
| 112 | 116 | $generator = new ContextGenerator($this->context); |
| 113 | - foreach ($generator->generate() as $context) { |
|
| 117 | + foreach ($generator->generate() as $context) |
|
| 118 | + { |
|
| 114 | 119 | $engine->reset($path, $context); |
| 115 | 120 | } |
| 116 | 121 | } |
@@ -122,7 +127,8 @@ discard block |
||
| 122 | 127 | */ |
| 123 | 128 | public function get(string $path): ViewInterface |
| 124 | 129 | { |
| 125 | - if ($this->cache?->has($this->context, $path)) { |
|
| 130 | + if ($this->cache?->has($this->context, $path)) |
|
| 131 | + { |
|
| 126 | 132 | return $this->cache->get($this->context, $path); |
| 127 | 133 | } |
| 128 | 134 | |
@@ -150,8 +156,10 @@ discard block |
||
| 150 | 156 | */ |
| 151 | 157 | private function findEngine(string $path): EngineInterface |
| 152 | 158 | { |
| 153 | - foreach ($this->engines as $engine) { |
|
| 154 | - if ($engine->getLoader()->exists($path)) { |
|
| 159 | + foreach ($this->engines as $engine) |
|
| 160 | + { |
|
| 161 | + if ($engine->getLoader()->exists($path)) |
|
| 162 | + { |
|
| 155 | 163 | return $engine; |
| 156 | 164 | } |
| 157 | 165 | } |
@@ -24,7 +24,8 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | public function load(mixed $resource, string $type = null): RouteCollection |
| 26 | 26 | { |
| 27 | - if (!\file_exists($resource)) { |
|
| 27 | + if (!\file_exists($resource)) |
|
| 28 | + { |
|
| 28 | 29 | throw new LoaderLoadException(\sprintf('File [%s] does not exist.', $resource)); |
| 29 | 30 | } |
| 30 | 31 | |
@@ -42,7 +42,8 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function setLocale(string $locale): void |
| 44 | 44 | { |
| 45 | - if (!$this->catalogueManager->has($locale)) { |
|
| 45 | + if (!$this->catalogueManager->has($locale)) |
|
| 46 | + { |
|
| 46 | 47 | throw new LocaleException($locale); |
| 47 | 48 | } |
| 48 | 49 | |
@@ -94,7 +95,8 @@ discard block |
||
| 94 | 95 | $domain ??= $this->config->getDefaultDomain(); |
| 95 | 96 | $locale ??= $this->locale; |
| 96 | 97 | |
| 97 | - try { |
|
| 98 | + try |
|
| 99 | + { |
|
| 98 | 100 | $message = $this->get($locale, $domain, $id); |
| 99 | 101 | |
| 100 | 102 | $pluralized = $this->identityTranslator->trans( |
@@ -103,12 +105,15 @@ discard block |
||
| 103 | 105 | null, |
| 104 | 106 | $locale |
| 105 | 107 | ); |
| 106 | - } catch (\InvalidArgumentException $e) { |
|
| 108 | + } |
|
| 109 | + catch (\InvalidArgumentException $e) |
|
| 110 | + { |
|
| 107 | 111 | //Wrapping into more explanatory exception |
| 108 | 112 | throw new PluralizationException($e->getMessage(), $e->getCode(), $e); |
| 109 | 113 | } |
| 110 | 114 | |
| 111 | - if (empty($parameters['n']) && is_numeric($number)) { |
|
| 115 | + if (empty($parameters['n']) && is_numeric($number)) |
|
| 116 | + { |
|
| 112 | 117 | $parameters['n'] = $number; |
| 113 | 118 | } |
| 114 | 119 | |
@@ -132,13 +137,18 @@ discard block |
||
| 132 | 137 | string $postfix = '}' |
| 133 | 138 | ): string { |
| 134 | 139 | $replaces = []; |
| 135 | - foreach ($values as $key => $value) { |
|
| 140 | + foreach ($values as $key => $value) |
|
| 141 | + { |
|
| 136 | 142 | $value = (\is_array($value) || $value instanceof \Closure) ? '' : $value; |
| 137 | 143 | |
| 138 | - if (\is_object($value)) { |
|
| 139 | - if (\method_exists($value, '__toString')) { |
|
| 144 | + if (\is_object($value)) |
|
| 145 | + { |
|
| 146 | + if (\method_exists($value, '__toString')) |
|
| 147 | + { |
|
| 140 | 148 | $value = $value->__toString(); |
| 141 | - } else { |
|
| 149 | + } |
|
| 150 | + else |
|
| 151 | + { |
|
| 142 | 152 | $value = ''; |
| 143 | 153 | } |
| 144 | 154 | } |
@@ -163,18 +173,21 @@ discard block |
||
| 163 | 173 | */ |
| 164 | 174 | protected function get(string &$locale, string $domain, string $string): string |
| 165 | 175 | { |
| 166 | - if ($this->catalogueManager->get($locale)->has($domain, $string)) { |
|
| 176 | + if ($this->catalogueManager->get($locale)->has($domain, $string)) |
|
| 177 | + { |
|
| 167 | 178 | return $this->catalogueManager->get($locale)->get($domain, $string); |
| 168 | 179 | } |
| 169 | 180 | |
| 170 | 181 | $locale = $this->config->getFallbackLocale(); |
| 171 | 182 | |
| 172 | - if ($this->catalogueManager->get($locale)->has($domain, $string)) { |
|
| 183 | + if ($this->catalogueManager->get($locale)->has($domain, $string)) |
|
| 184 | + { |
|
| 173 | 185 | return $this->catalogueManager->get($locale)->get($domain, $string); |
| 174 | 186 | } |
| 175 | 187 | |
| 176 | 188 | // we can automatically register message |
| 177 | - if ($this->config->isAutoRegisterMessages()) { |
|
| 189 | + if ($this->config->isAutoRegisterMessages()) |
|
| 190 | + { |
|
| 178 | 191 | $this->catalogueManager->get($locale)->set($domain, $string, $string); |
| 179 | 192 | $this->catalogueManager->save($locale); |
| 180 | 193 | } |