@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | use Spiral\Translator\Exception\TranslatorException; |
| 8 | 8 | use Spiral\Translator\TranslatorInterface; |
| 9 | 9 | |
| 10 | -if (!\function_exists('l')) { |
|
| 10 | +if (!\function_exists('l')){ |
|
| 11 | 11 | /** |
| 12 | 12 | * Translate message using default or specific bundle name. |
| 13 | 13 | * |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | { |
| 23 | 23 | /** @psalm-suppress InternalMethod */ |
| 24 | 24 | $container = ContainerScope::getContainer(); |
| 25 | - if ($container === null || !$container->has(TranslatorInterface::class)) { |
|
| 25 | + if ($container === null || !$container->has(TranslatorInterface::class)){ |
|
| 26 | 26 | throw new ScopeException( |
| 27 | 27 | '`TranslatorInterface` binding is missing or container scope is not set' |
| 28 | 28 | ); |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | } |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | -if (!\function_exists('p')) { |
|
| 38 | +if (!\function_exists('p')){ |
|
| 39 | 39 | /** |
| 40 | 40 | * Pluralize string using language pluralization options and specified numeric value. |
| 41 | 41 | * |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | { |
| 52 | 52 | /** @psalm-suppress InternalMethod */ |
| 53 | 53 | $container = ContainerScope::getContainer(); |
| 54 | - if (empty($container) || !$container->has(TranslatorInterface::class)) { |
|
| 54 | + if (empty($container) || !$container->has(TranslatorInterface::class)){ |
|
| 55 | 55 | throw new ScopeException( |
| 56 | 56 | '`TranslatorInterface` binding is missing or container scope is not set' |
| 57 | 57 | ); |
@@ -7,7 +7,8 @@ discard block |
||
| 7 | 7 | use Spiral\Translator\Exception\TranslatorException; |
| 8 | 8 | use Spiral\Translator\TranslatorInterface; |
| 9 | 9 | |
| 10 | -if (!\function_exists('l')) { |
|
| 10 | +if (!\function_exists('l')) |
|
| 11 | +{ |
|
| 11 | 12 | /** |
| 12 | 13 | * Translate message using default or specific bundle name. |
| 13 | 14 | * |
@@ -22,7 +23,8 @@ discard block |
||
| 22 | 23 | { |
| 23 | 24 | /** @psalm-suppress InternalMethod */ |
| 24 | 25 | $container = ContainerScope::getContainer(); |
| 25 | - if ($container === null || !$container->has(TranslatorInterface::class)) { |
|
| 26 | + if ($container === null || !$container->has(TranslatorInterface::class)) |
|
| 27 | + { |
|
| 26 | 28 | throw new ScopeException( |
| 27 | 29 | '`TranslatorInterface` binding is missing or container scope is not set' |
| 28 | 30 | ); |
@@ -35,7 +37,8 @@ discard block |
||
| 35 | 37 | } |
| 36 | 38 | } |
| 37 | 39 | |
| 38 | -if (!\function_exists('p')) { |
|
| 40 | +if (!\function_exists('p')) |
|
| 41 | +{ |
|
| 39 | 42 | /** |
| 40 | 43 | * Pluralize string using language pluralization options and specified numeric value. |
| 41 | 44 | * |
@@ -51,7 +54,8 @@ discard block |
||
| 51 | 54 | { |
| 52 | 55 | /** @psalm-suppress InternalMethod */ |
| 53 | 56 | $container = ContainerScope::getContainer(); |
| 54 | - if (empty($container) || !$container->has(TranslatorInterface::class)) { |
|
| 57 | + if (empty($container) || !$container->has(TranslatorInterface::class)) |
|
| 58 | + { |
|
| 55 | 59 | throw new ScopeException( |
| 56 | 60 | '`TranslatorInterface` binding is missing or container scope is not set' |
| 57 | 61 | ); |
@@ -31,7 +31,7 @@ |
||
| 31 | 31 | |
| 32 | 32 | public function loadCatalogue(string $locale): CatalogueInterface |
| 33 | 33 | { |
| 34 | - if (!$this->hasLocale($locale)) { |
|
| 34 | + if (!$this->hasLocale($locale)){ |
|
| 35 | 35 | throw new LocaleException($locale); |
| 36 | 36 | } |
| 37 | 37 | |
@@ -31,7 +31,8 @@ |
||
| 31 | 31 | |
| 32 | 32 | public function loadCatalogue(string $locale): CatalogueInterface |
| 33 | 33 | { |
| 34 | - if (!$this->hasLocale($locale)) { |
|
| 34 | + if (!$this->hasLocale($locale)) |
|
| 35 | + { |
|
| 35 | 36 | throw new LocaleException($locale); |
| 36 | 37 | } |
| 37 | 38 | |
@@ -24,18 +24,18 @@ discard block |
||
| 24 | 24 | public function __construct( |
| 25 | 25 | private readonly LoaderInterface $loader, |
| 26 | 26 | CacheInterface $cache = null |
| 27 | - ) { |
|
| 27 | + ){ |
|
| 28 | 28 | $this->cache = $cache ?? new NullCache(); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | public function getLocales(): array |
| 32 | 32 | { |
| 33 | - if ($this->locales !== []) { |
|
| 33 | + if ($this->locales !== []){ |
|
| 34 | 34 | return $this->locales; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | $this->locales = (array)$this->cache->getLocales(); |
| 38 | - if ($this->locales === []) { |
|
| 38 | + if ($this->locales === []){ |
|
| 39 | 39 | $this->locales = $this->loader->getLocales(); |
| 40 | 40 | $this->cache->setLocales($this->locales); |
| 41 | 41 | } |
@@ -45,14 +45,14 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | public function load(string $locale): CatalogueInterface |
| 47 | 47 | { |
| 48 | - if (isset($this->catalogues[$locale])) { |
|
| 48 | + if (isset($this->catalogues[$locale])){ |
|
| 49 | 49 | return $this->catalogues[$locale]; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | $data = (array)$this->cache->loadLocale($locale); |
| 53 | - if (!empty($data)) { |
|
| 53 | + if (!empty($data)){ |
|
| 54 | 54 | $this->catalogues[$locale] = new Catalogue($locale, $data); |
| 55 | - } else { |
|
| 55 | + }else{ |
|
| 56 | 56 | $this->catalogues[$locale] = $this->loader->loadCatalogue($locale); |
| 57 | 57 | } |
| 58 | 58 | |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | public function reset(): void |
| 81 | 81 | { |
| 82 | 82 | $this->cache->setLocales(null); |
| 83 | - foreach ($this->getLocales() as $locale) { |
|
| 83 | + foreach ($this->getLocales() as $locale){ |
|
| 84 | 84 | $this->cache->saveLocale($locale, null); |
| 85 | 85 | } |
| 86 | 86 | |
@@ -30,12 +30,14 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | public function getLocales(): array |
| 32 | 32 | { |
| 33 | - if ($this->locales !== []) { |
|
| 33 | + if ($this->locales !== []) |
|
| 34 | + { |
|
| 34 | 35 | return $this->locales; |
| 35 | 36 | } |
| 36 | 37 | |
| 37 | 38 | $this->locales = (array)$this->cache->getLocales(); |
| 38 | - if ($this->locales === []) { |
|
| 39 | + if ($this->locales === []) |
|
| 40 | + { |
|
| 39 | 41 | $this->locales = $this->loader->getLocales(); |
| 40 | 42 | $this->cache->setLocales($this->locales); |
| 41 | 43 | } |
@@ -45,14 +47,18 @@ discard block |
||
| 45 | 47 | |
| 46 | 48 | public function load(string $locale): CatalogueInterface |
| 47 | 49 | { |
| 48 | - if (isset($this->catalogues[$locale])) { |
|
| 50 | + if (isset($this->catalogues[$locale])) |
|
| 51 | + { |
|
| 49 | 52 | return $this->catalogues[$locale]; |
| 50 | 53 | } |
| 51 | 54 | |
| 52 | 55 | $data = (array)$this->cache->loadLocale($locale); |
| 53 | - if (!empty($data)) { |
|
| 56 | + if (!empty($data)) |
|
| 57 | + { |
|
| 54 | 58 | $this->catalogues[$locale] = new Catalogue($locale, $data); |
| 55 | - } else { |
|
| 59 | + } |
|
| 60 | + else |
|
| 61 | + { |
|
| 56 | 62 | $this->catalogues[$locale] = $this->loader->loadCatalogue($locale); |
| 57 | 63 | } |
| 58 | 64 | |
@@ -80,7 +86,8 @@ discard block |
||
| 80 | 86 | public function reset(): void |
| 81 | 87 | { |
| 82 | 88 | $this->cache->setLocales(null); |
| 83 | - foreach ($this->getLocales() as $locale) { |
|
| 89 | + foreach ($this->getLocales() as $locale) |
|
| 90 | + { |
|
| 84 | 91 | $this->cache->saveLocale($locale, null); |
| 85 | 92 | } |
| 86 | 93 | |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | public function __construct( |
| 18 | 18 | private readonly TranslatorConfig $config |
| 19 | - ) { |
|
| 19 | + ){ |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | public function hasLocale(string $locale): bool |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | public function getLocales(): array |
| 30 | 30 | { |
| 31 | - if (!\is_dir($this->config->getLocalesDirectory())) { |
|
| 31 | + if (!\is_dir($this->config->getLocalesDirectory())){ |
|
| 32 | 32 | return []; |
| 33 | 33 | } |
| 34 | 34 | |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | $locales = []; |
| 39 | 39 | |
| 40 | - foreach ($finder->directories() as $directory) { |
|
| 40 | + foreach ($finder->directories() as $directory){ |
|
| 41 | 41 | $locales[] = $directory->getFilename(); |
| 42 | 42 | } |
| 43 | 43 | |
@@ -49,14 +49,14 @@ discard block |
||
| 49 | 49 | $locale = \preg_replace('/[^a-zA-Z_]/', '', \mb_strtolower($locale)); |
| 50 | 50 | $catalogue = new Catalogue($locale); |
| 51 | 51 | |
| 52 | - if (!$this->hasLocale($locale)) { |
|
| 52 | + if (!$this->hasLocale($locale)){ |
|
| 53 | 53 | return $catalogue; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | $finder = new Finder(); |
| 57 | 57 | $finder->in($this->config->getLocaleDirectory($locale)); |
| 58 | 58 | |
| 59 | - foreach ($finder->getIterator() as $file) { |
|
| 59 | + foreach ($finder->getIterator() as $file){ |
|
| 60 | 60 | $this->getLogger()->info( |
| 61 | 61 | \sprintf( |
| 62 | 62 | "found locale domain file '%s'", |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | //Per application agreement domain name must present in filename |
| 69 | 69 | $domain = \strstr($file->getFilename(), '.', true); |
| 70 | 70 | |
| 71 | - if (!$this->config->hasLoader($file->getExtension())) { |
|
| 71 | + if (!$this->config->hasLoader($file->getExtension())){ |
|
| 72 | 72 | $this->getLogger()->warning( |
| 73 | 73 | \sprintf( |
| 74 | 74 | "unable to load domain file '%s', no loader found", |
@@ -28,7 +28,8 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | public function getLocales(): array |
| 30 | 30 | { |
| 31 | - if (!\is_dir($this->config->getLocalesDirectory())) { |
|
| 31 | + if (!\is_dir($this->config->getLocalesDirectory())) |
|
| 32 | + { |
|
| 32 | 33 | return []; |
| 33 | 34 | } |
| 34 | 35 | |
@@ -37,7 +38,8 @@ discard block |
||
| 37 | 38 | |
| 38 | 39 | $locales = []; |
| 39 | 40 | |
| 40 | - foreach ($finder->directories() as $directory) { |
|
| 41 | + foreach ($finder->directories() as $directory) |
|
| 42 | + { |
|
| 41 | 43 | $locales[] = $directory->getFilename(); |
| 42 | 44 | } |
| 43 | 45 | |
@@ -49,14 +51,16 @@ discard block |
||
| 49 | 51 | $locale = \preg_replace('/[^a-zA-Z_]/', '', \mb_strtolower($locale)); |
| 50 | 52 | $catalogue = new Catalogue($locale); |
| 51 | 53 | |
| 52 | - if (!$this->hasLocale($locale)) { |
|
| 54 | + if (!$this->hasLocale($locale)) |
|
| 55 | + { |
|
| 53 | 56 | return $catalogue; |
| 54 | 57 | } |
| 55 | 58 | |
| 56 | 59 | $finder = new Finder(); |
| 57 | 60 | $finder->in($this->config->getLocaleDirectory($locale)); |
| 58 | 61 | |
| 59 | - foreach ($finder->getIterator() as $file) { |
|
| 62 | + foreach ($finder->getIterator() as $file) |
|
| 63 | + { |
|
| 60 | 64 | $this->getLogger()->info( |
| 61 | 65 | \sprintf( |
| 62 | 66 | "found locale domain file '%s'", |
@@ -68,7 +72,8 @@ discard block |
||
| 68 | 72 | //Per application agreement domain name must present in filename |
| 69 | 73 | $domain = \strstr($file->getFilename(), '.', true); |
| 70 | 74 | |
| 71 | - if (!$this->config->hasLoader($file->getExtension())) { |
|
| 75 | + if (!$this->config->hasLoader($file->getExtension())) |
|
| 76 | + { |
|
| 72 | 77 | $this->getLogger()->warning( |
| 73 | 78 | \sprintf( |
| 74 | 79 | "unable to load domain file '%s', no loader found", |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | /** @internal */ |
| 27 | 27 | private readonly IdentityTranslator $identityTranslator = new IdentityTranslator(), |
| 28 | 28 | private readonly ?EventDispatcherInterface $dispatcher = null, |
| 29 | - ) { |
|
| 29 | + ){ |
|
| 30 | 30 | $this->locale = $this->config->getDefaultLocale(); |
| 31 | 31 | $this->catalogueManager->load($this->locale); |
| 32 | 32 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function setLocale(string $locale): void |
| 43 | 43 | { |
| 44 | - if (!$this->catalogueManager->has($locale)) { |
|
| 44 | + if (!$this->catalogueManager->has($locale)){ |
|
| 45 | 45 | throw new LocaleException($locale); |
| 46 | 46 | } |
| 47 | 47 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | public function transChoice( |
| 87 | 87 | string $id, |
| 88 | - string|int $number, |
|
| 88 | + string | int $number, |
|
| 89 | 89 | array $parameters = [], |
| 90 | 90 | string $domain = null, |
| 91 | 91 | string $locale = null |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | $domain = $domain ?? $this->config->getDefaultDomain(); |
| 94 | 94 | $locale = $locale ?? $this->locale; |
| 95 | 95 | |
| 96 | - try { |
|
| 96 | + try{ |
|
| 97 | 97 | $message = $this->get($locale, $domain, $id); |
| 98 | 98 | |
| 99 | 99 | $pluralized = $this->identityTranslator->trans( |
@@ -102,12 +102,12 @@ discard block |
||
| 102 | 102 | null, |
| 103 | 103 | $locale |
| 104 | 104 | ); |
| 105 | - } catch (\InvalidArgumentException $e) { |
|
| 105 | + }catch (\InvalidArgumentException $e){ |
|
| 106 | 106 | //Wrapping into more explanatory exception |
| 107 | 107 | throw new PluralizationException($e->getMessage(), $e->getCode(), $e); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - if (empty($parameters['n']) && is_numeric($number)) { |
|
| 110 | + if (empty($parameters['n']) && is_numeric($number)){ |
|
| 111 | 111 | $parameters['n'] = $number; |
| 112 | 112 | } |
| 113 | 113 | |
@@ -131,18 +131,18 @@ discard block |
||
| 131 | 131 | string $postfix = '}' |
| 132 | 132 | ): string { |
| 133 | 133 | $replaces = []; |
| 134 | - foreach ($values as $key => $value) { |
|
| 134 | + foreach ($values as $key => $value){ |
|
| 135 | 135 | $value = (\is_array($value) || $value instanceof \Closure) ? '' : $value; |
| 136 | 136 | |
| 137 | - if (\is_object($value)) { |
|
| 138 | - if (\method_exists($value, '__toString')) { |
|
| 137 | + if (\is_object($value)){ |
|
| 138 | + if (\method_exists($value, '__toString')){ |
|
| 139 | 139 | $value = $value->__toString(); |
| 140 | - } else { |
|
| 140 | + }else{ |
|
| 141 | 141 | $value = ''; |
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - $replaces[$prefix . $key . $postfix] = $value; |
|
| 145 | + $replaces[$prefix.$key.$postfix] = $value; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | return \strtr($string, $replaces); |
@@ -162,18 +162,18 @@ discard block |
||
| 162 | 162 | */ |
| 163 | 163 | protected function get(string &$locale, string $domain, string $string): string |
| 164 | 164 | { |
| 165 | - if ($this->catalogueManager->get($locale)->has($domain, $string)) { |
|
| 165 | + if ($this->catalogueManager->get($locale)->has($domain, $string)){ |
|
| 166 | 166 | return $this->catalogueManager->get($locale)->get($domain, $string); |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | $locale = $this->config->getFallbackLocale(); |
| 170 | 170 | |
| 171 | - if ($this->catalogueManager->get($locale)->has($domain, $string)) { |
|
| 171 | + if ($this->catalogueManager->get($locale)->has($domain, $string)){ |
|
| 172 | 172 | return $this->catalogueManager->get($locale)->get($domain, $string); |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | // we can automatically register message |
| 176 | - if ($this->config->isAutoRegisterMessages()) { |
|
| 176 | + if ($this->config->isAutoRegisterMessages()){ |
|
| 177 | 177 | $this->catalogueManager->get($locale)->set($domain, $string, $string); |
| 178 | 178 | $this->catalogueManager->save($locale); |
| 179 | 179 | } |
@@ -41,7 +41,8 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function setLocale(string $locale): void |
| 43 | 43 | { |
| 44 | - if (!$this->catalogueManager->has($locale)) { |
|
| 44 | + if (!$this->catalogueManager->has($locale)) |
|
| 45 | + { |
|
| 45 | 46 | throw new LocaleException($locale); |
| 46 | 47 | } |
| 47 | 48 | |
@@ -93,7 +94,8 @@ discard block |
||
| 93 | 94 | $domain = $domain ?? $this->config->getDefaultDomain(); |
| 94 | 95 | $locale = $locale ?? $this->locale; |
| 95 | 96 | |
| 96 | - try { |
|
| 97 | + try |
|
| 98 | + { |
|
| 97 | 99 | $message = $this->get($locale, $domain, $id); |
| 98 | 100 | |
| 99 | 101 | $pluralized = $this->identityTranslator->trans( |
@@ -102,12 +104,15 @@ discard block |
||
| 102 | 104 | null, |
| 103 | 105 | $locale |
| 104 | 106 | ); |
| 105 | - } catch (\InvalidArgumentException $e) { |
|
| 107 | + } |
|
| 108 | + catch (\InvalidArgumentException $e) |
|
| 109 | + { |
|
| 106 | 110 | //Wrapping into more explanatory exception |
| 107 | 111 | throw new PluralizationException($e->getMessage(), $e->getCode(), $e); |
| 108 | 112 | } |
| 109 | 113 | |
| 110 | - if (empty($parameters['n']) && is_numeric($number)) { |
|
| 114 | + if (empty($parameters['n']) && is_numeric($number)) |
|
| 115 | + { |
|
| 111 | 116 | $parameters['n'] = $number; |
| 112 | 117 | } |
| 113 | 118 | |
@@ -131,13 +136,18 @@ discard block |
||
| 131 | 136 | string $postfix = '}' |
| 132 | 137 | ): string { |
| 133 | 138 | $replaces = []; |
| 134 | - foreach ($values as $key => $value) { |
|
| 139 | + foreach ($values as $key => $value) |
|
| 140 | + { |
|
| 135 | 141 | $value = (\is_array($value) || $value instanceof \Closure) ? '' : $value; |
| 136 | 142 | |
| 137 | - if (\is_object($value)) { |
|
| 138 | - if (\method_exists($value, '__toString')) { |
|
| 143 | + if (\is_object($value)) |
|
| 144 | + { |
|
| 145 | + if (\method_exists($value, '__toString')) |
|
| 146 | + { |
|
| 139 | 147 | $value = $value->__toString(); |
| 140 | - } else { |
|
| 148 | + } |
|
| 149 | + else |
|
| 150 | + { |
|
| 141 | 151 | $value = ''; |
| 142 | 152 | } |
| 143 | 153 | } |
@@ -162,18 +172,21 @@ discard block |
||
| 162 | 172 | */ |
| 163 | 173 | protected function get(string &$locale, string $domain, string $string): string |
| 164 | 174 | { |
| 165 | - if ($this->catalogueManager->get($locale)->has($domain, $string)) { |
|
| 175 | + if ($this->catalogueManager->get($locale)->has($domain, $string)) |
|
| 176 | + { |
|
| 166 | 177 | return $this->catalogueManager->get($locale)->get($domain, $string); |
| 167 | 178 | } |
| 168 | 179 | |
| 169 | 180 | $locale = $this->config->getFallbackLocale(); |
| 170 | 181 | |
| 171 | - if ($this->catalogueManager->get($locale)->has($domain, $string)) { |
|
| 182 | + if ($this->catalogueManager->get($locale)->has($domain, $string)) |
|
| 183 | + { |
|
| 172 | 184 | return $this->catalogueManager->get($locale)->get($domain, $string); |
| 173 | 185 | } |
| 174 | 186 | |
| 175 | 187 | // we can automatically register message |
| 176 | - if ($this->config->isAutoRegisterMessages()) { |
|
| 188 | + if ($this->config->isAutoRegisterMessages()) |
|
| 189 | + { |
|
| 177 | 190 | $this->catalogueManager->get($locale)->set($domain, $string, $string); |
| 178 | 191 | $this->catalogueManager->save($locale); |
| 179 | 192 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | public function __construct( |
| 20 | 20 | private readonly string $locale, |
| 21 | 21 | private array $data = [] |
| 22 | - ) { |
|
| 22 | + ){ |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public function getLocale(): string |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | public function has(string $domain, string $id): bool |
| 36 | 36 | { |
| 37 | - if (!isset($this->data[$domain])) { |
|
| 37 | + if (!isset($this->data[$domain])){ |
|
| 38 | 38 | return false; |
| 39 | 39 | } |
| 40 | 40 | |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | public function get(string $domain, string $id): string |
| 45 | 45 | { |
| 46 | - if (!$this->has($domain, $id)) { |
|
| 46 | + if (!$this->has($domain, $id)){ |
|
| 47 | 47 | throw new CatalogueException(\sprintf("Undefined string in domain '%s'", $domain)); |
| 48 | 48 | } |
| 49 | 49 | |
@@ -66,15 +66,15 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function mergeFrom(MessageCatalogue $catalogue, bool $follow = true): void |
| 68 | 68 | { |
| 69 | - foreach ($catalogue->all() as $domain => $messages) { |
|
| 70 | - if (!isset($this->data[$domain])) { |
|
| 69 | + foreach ($catalogue->all() as $domain => $messages){ |
|
| 70 | + if (!isset($this->data[$domain])){ |
|
| 71 | 71 | $this->data[$domain] = []; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - if ($follow) { |
|
| 74 | + if ($follow){ |
|
| 75 | 75 | //MessageCatalogue string has higher priority that string stored in memory |
| 76 | 76 | $this->data[$domain] = \array_merge($messages, $this->data[$domain]); |
| 77 | - } else { |
|
| 77 | + }else{ |
|
| 78 | 78 | $this->data[$domain] = \array_merge($this->data[$domain], $messages); |
| 79 | 79 | } |
| 80 | 80 | } |
@@ -34,7 +34,8 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | public function has(string $domain, string $id): bool |
| 36 | 36 | { |
| 37 | - if (!isset($this->data[$domain])) { |
|
| 37 | + if (!isset($this->data[$domain])) |
|
| 38 | + { |
|
| 38 | 39 | return false; |
| 39 | 40 | } |
| 40 | 41 | |
@@ -43,7 +44,8 @@ discard block |
||
| 43 | 44 | |
| 44 | 45 | public function get(string $domain, string $id): string |
| 45 | 46 | { |
| 46 | - if (!$this->has($domain, $id)) { |
|
| 47 | + if (!$this->has($domain, $id)) |
|
| 48 | + { |
|
| 47 | 49 | throw new CatalogueException(\sprintf("Undefined string in domain '%s'", $domain)); |
| 48 | 50 | } |
| 49 | 51 | |
@@ -66,15 +68,20 @@ discard block |
||
| 66 | 68 | */ |
| 67 | 69 | public function mergeFrom(MessageCatalogue $catalogue, bool $follow = true): void |
| 68 | 70 | { |
| 69 | - foreach ($catalogue->all() as $domain => $messages) { |
|
| 70 | - if (!isset($this->data[$domain])) { |
|
| 71 | + foreach ($catalogue->all() as $domain => $messages) |
|
| 72 | + { |
|
| 73 | + if (!isset($this->data[$domain])) |
|
| 74 | + { |
|
| 71 | 75 | $this->data[$domain] = []; |
| 72 | 76 | } |
| 73 | 77 | |
| 74 | - if ($follow) { |
|
| 78 | + if ($follow) |
|
| 79 | + { |
|
| 75 | 80 | //MessageCatalogue string has higher priority that string stored in memory |
| 76 | 81 | $this->data[$domain] = \array_merge($messages, $this->data[$domain]); |
| 77 | - } else { |
|
| 82 | + } |
|
| 83 | + else |
|
| 84 | + { |
|
| 78 | 85 | $this->data[$domain] = \array_merge($this->data[$domain], $messages); |
| 79 | 86 | } |
| 80 | 87 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | public function __construct( |
| 32 | 32 | private readonly TranslatorConfig $config, |
| 33 | 33 | private readonly CatalogueInterface $catalogue |
| 34 | - ) { |
|
| 34 | + ){ |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function registerMessage(string $domain, string $string, bool $resolveDomain = true): void |
| 41 | 41 | { |
| 42 | - if ($resolveDomain) { |
|
| 42 | + if ($resolveDomain){ |
|
| 43 | 43 | $domain = $this->config->resolveDomain($domain); |
| 44 | 44 | } |
| 45 | 45 | |
@@ -58,9 +58,9 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | public function indexClasses(ScopedClassesInterface $locator): void |
| 60 | 60 | { |
| 61 | - foreach ($locator->getScopedClasses('translations', TranslatorTrait::class) as $class) { |
|
| 61 | + foreach ($locator->getScopedClasses('translations', TranslatorTrait::class) as $class){ |
|
| 62 | 62 | $strings = $this->fetchMessages($class, true); |
| 63 | - foreach ($strings as $string) { |
|
| 63 | + foreach ($strings as $string){ |
|
| 64 | 64 | $this->registerMessage($class->getName(), $string); |
| 65 | 65 | } |
| 66 | 66 | } |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | private function registerInvocations(array $invocations): void |
| 94 | 94 | { |
| 95 | - foreach ($invocations as $invocation) { |
|
| 96 | - if ($invocation->getArgument(0)->getType() != ReflectionArgument::STRING) { |
|
| 95 | + foreach ($invocations as $invocation){ |
|
| 96 | + if ($invocation->getArgument(0)->getType() != ReflectionArgument::STRING){ |
|
| 97 | 97 | //We can only index invocations with constant string arguments |
| 98 | 98 | continue; |
| 99 | 99 | } |
@@ -112,20 +112,20 @@ discard block |
||
| 112 | 112 | { |
| 113 | 113 | $target = $reflection->getDefaultProperties() + $reflection->getConstants(); |
| 114 | 114 | |
| 115 | - foreach ($reflection->getProperties() as $property) { |
|
| 116 | - if (\is_string($property->getDocComment()) && \strpos($property->getDocComment(), '@do-not-index')) { |
|
| 115 | + foreach ($reflection->getProperties() as $property){ |
|
| 116 | + if (\is_string($property->getDocComment()) && \strpos($property->getDocComment(), '@do-not-index')){ |
|
| 117 | 117 | unset($target[$property->getName()]); |
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | $strings = []; |
| 122 | 122 | \array_walk_recursive($target, function ($value) use (&$strings): void { |
| 123 | - if (\is_string($value) && Translator::isMessage($value)) { |
|
| 123 | + if (\is_string($value) && Translator::isMessage($value)){ |
|
| 124 | 124 | $strings[] = $this->prepareMessage($value); |
| 125 | 125 | } |
| 126 | 126 | }); |
| 127 | 127 | |
| 128 | - if ($inherit && $reflection->getParentClass()) { |
|
| 128 | + if ($inherit && $reflection->getParentClass()){ |
|
| 129 | 129 | //Joining strings data with parent class values (inheritance ON) - resolved into same |
| 130 | 130 | //domain on export |
| 131 | 131 | $strings = \array_merge( |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | //Translation using default bundle |
| 146 | 146 | $domain = $this->config->getDefaultDomain(); |
| 147 | 147 | |
| 148 | - if ($invocation->getName() === 'say') { |
|
| 148 | + if ($invocation->getName() === 'say'){ |
|
| 149 | 149 | //Let's try to confirm domain |
| 150 | 150 | $domain = $this->config->resolveDomain($invocation->getClass()); |
| 151 | 151 | } |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | default => null |
| 158 | 158 | }; |
| 159 | 159 | |
| 160 | - if (!empty($argument) && $argument->getType() === ReflectionArgument::STRING) { |
|
| 160 | + if (!empty($argument) && $argument->getType() === ReflectionArgument::STRING){ |
|
| 161 | 161 | //Domain specified in arguments |
| 162 | 162 | $domain = $this->config->resolveDomain($argument->stringValue()); |
| 163 | 163 | } |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | private function prepareMessage(string $string): string |
| 172 | 172 | { |
| 173 | - if (Translator::isMessage($string)) { |
|
| 173 | + if (Translator::isMessage($string)){ |
|
| 174 | 174 | $string = \substr($string, 2, -2); |
| 175 | 175 | } |
| 176 | 176 | |
@@ -39,7 +39,8 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function registerMessage(string $domain, string $string, bool $resolveDomain = true): void |
| 41 | 41 | { |
| 42 | - if ($resolveDomain) { |
|
| 42 | + if ($resolveDomain) |
|
| 43 | + { |
|
| 43 | 44 | $domain = $this->config->resolveDomain($domain); |
| 44 | 45 | } |
| 45 | 46 | |
@@ -58,9 +59,11 @@ discard block |
||
| 58 | 59 | */ |
| 59 | 60 | public function indexClasses(ScopedClassesInterface $locator): void |
| 60 | 61 | { |
| 61 | - foreach ($locator->getScopedClasses('translations', TranslatorTrait::class) as $class) { |
|
| 62 | + foreach ($locator->getScopedClasses('translations', TranslatorTrait::class) as $class) |
|
| 63 | + { |
|
| 62 | 64 | $strings = $this->fetchMessages($class, true); |
| 63 | - foreach ($strings as $string) { |
|
| 65 | + foreach ($strings as $string) |
|
| 66 | + { |
|
| 64 | 67 | $this->registerMessage($class->getName(), $string); |
| 65 | 68 | } |
| 66 | 69 | } |
@@ -92,8 +95,10 @@ discard block |
||
| 92 | 95 | */ |
| 93 | 96 | private function registerInvocations(array $invocations): void |
| 94 | 97 | { |
| 95 | - foreach ($invocations as $invocation) { |
|
| 96 | - if ($invocation->getArgument(0)->getType() != ReflectionArgument::STRING) { |
|
| 98 | + foreach ($invocations as $invocation) |
|
| 99 | + { |
|
| 100 | + if ($invocation->getArgument(0)->getType() != ReflectionArgument::STRING) |
|
| 101 | + { |
|
| 97 | 102 | //We can only index invocations with constant string arguments |
| 98 | 103 | continue; |
| 99 | 104 | } |
@@ -112,20 +117,24 @@ discard block |
||
| 112 | 117 | { |
| 113 | 118 | $target = $reflection->getDefaultProperties() + $reflection->getConstants(); |
| 114 | 119 | |
| 115 | - foreach ($reflection->getProperties() as $property) { |
|
| 116 | - if (\is_string($property->getDocComment()) && \strpos($property->getDocComment(), '@do-not-index')) { |
|
| 120 | + foreach ($reflection->getProperties() as $property) |
|
| 121 | + { |
|
| 122 | + if (\is_string($property->getDocComment()) && \strpos($property->getDocComment(), '@do-not-index')) |
|
| 123 | + { |
|
| 117 | 124 | unset($target[$property->getName()]); |
| 118 | 125 | } |
| 119 | 126 | } |
| 120 | 127 | |
| 121 | 128 | $strings = []; |
| 122 | 129 | \array_walk_recursive($target, function ($value) use (&$strings): void { |
| 123 | - if (\is_string($value) && Translator::isMessage($value)) { |
|
| 130 | + if (\is_string($value) && Translator::isMessage($value)) |
|
| 131 | + { |
|
| 124 | 132 | $strings[] = $this->prepareMessage($value); |
| 125 | 133 | } |
| 126 | 134 | }); |
| 127 | 135 | |
| 128 | - if ($inherit && $reflection->getParentClass()) { |
|
| 136 | + if ($inherit && $reflection->getParentClass()) |
|
| 137 | + { |
|
| 129 | 138 | //Joining strings data with parent class values (inheritance ON) - resolved into same |
| 130 | 139 | //domain on export |
| 131 | 140 | $strings = \array_merge( |
@@ -145,7 +154,8 @@ discard block |
||
| 145 | 154 | //Translation using default bundle |
| 146 | 155 | $domain = $this->config->getDefaultDomain(); |
| 147 | 156 | |
| 148 | - if ($invocation->getName() === 'say') { |
|
| 157 | + if ($invocation->getName() === 'say') |
|
| 158 | + { |
|
| 149 | 159 | //Let's try to confirm domain |
| 150 | 160 | $domain = $this->config->resolveDomain($invocation->getClass()); |
| 151 | 161 | } |
@@ -157,7 +167,8 @@ discard block |
||
| 157 | 167 | default => null |
| 158 | 168 | }; |
| 159 | 169 | |
| 160 | - if (!empty($argument) && $argument->getType() === ReflectionArgument::STRING) { |
|
| 170 | + if (!empty($argument) && $argument->getType() === ReflectionArgument::STRING) |
|
| 171 | + { |
|
| 161 | 172 | //Domain specified in arguments |
| 162 | 173 | $domain = $this->config->resolveDomain($argument->stringValue()); |
| 163 | 174 | } |
@@ -170,7 +181,8 @@ discard block |
||
| 170 | 181 | */ |
| 171 | 182 | private function prepareMessage(string $string): string |
| 172 | 183 | { |
| 173 | - if (Translator::isMessage($string)) { |
|
| 184 | + if (Translator::isMessage($string)) |
|
| 185 | + { |
|
| 174 | 186 | $string = \substr($string, 2, -2); |
| 175 | 187 | } |
| 176 | 188 | |
@@ -14,16 +14,16 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | public function __construct( |
| 16 | 16 | private DateTimeFactoryInterface $factory = new DateTimeFactory() |
| 17 | - ) { |
|
| 17 | + ){ |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | public function create(mixed $duration): \DateInterval |
| 21 | 21 | { |
| 22 | - try { |
|
| 22 | + try{ |
|
| 23 | 23 | return $this->createOrFail($duration); |
| 24 | - } catch (\InvalidArgumentException $e) { |
|
| 24 | + }catch (\InvalidArgumentException $e){ |
|
| 25 | 25 | throw $e; |
| 26 | - } catch (\Throwable $e) { |
|
| 26 | + }catch (\Throwable $e){ |
|
| 27 | 27 | throw new \InvalidArgumentException($e->getMessage(), (int)$e->getCode(), $e); |
| 28 | 28 | } |
| 29 | 29 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | $duration instanceof \DateInterval => $duration, |
| 45 | 45 | $duration instanceof \DateTimeInterface => $this->factory->now()->diff($duration), |
| 46 | 46 | \is_string($duration) => new \DateInterval($duration), |
| 47 | - \is_int($duration) => new \DateInterval('PT' . $duration . 'S'), |
|
| 47 | + \is_int($duration) => new \DateInterval('PT'.$duration.'S'), |
|
| 48 | 48 | $duration === null => new \DateInterval('PT0S'), |
| 49 | 49 | default => throw new \InvalidArgumentException( |
| 50 | 50 | \sprintf(self::ERROR_INVALID_INTERVAL_TYPE, \get_debug_type($duration)) |
@@ -19,11 +19,16 @@ |
||
| 19 | 19 | |
| 20 | 20 | public function create(mixed $duration): \DateInterval |
| 21 | 21 | { |
| 22 | - try { |
|
| 22 | + try |
|
| 23 | + { |
|
| 23 | 24 | return $this->createOrFail($duration); |
| 24 | - } catch (\InvalidArgumentException $e) { |
|
| 25 | + } |
|
| 26 | + catch (\InvalidArgumentException $e) |
|
| 27 | + { |
|
| 25 | 28 | throw $e; |
| 26 | - } catch (\Throwable $e) { |
|
| 29 | + } |
|
| 30 | + catch (\Throwable $e) |
|
| 31 | + { |
|
| 27 | 32 | throw new \InvalidArgumentException($e->getMessage(), (int)$e->getCode(), $e); |
| 28 | 33 | } |
| 29 | 34 | } |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | private function bootResolvers(array $config): void |
| 53 | 53 | { |
| 54 | - foreach ($config['resolvers'] ?? [] as $name => $child) { |
|
| 55 | - if (!\is_string($name)) { |
|
| 54 | + foreach ($config['resolvers'] ?? [] as $name => $child){ |
|
| 55 | + if (!\is_string($name)){ |
|
| 56 | 56 | throw new InvalidArgumentException( |
| 57 | 57 | \vsprintf('Distribution driver config key must be a string, but %s given', [ |
| 58 | 58 | \get_debug_type($child), |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | ); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - if (!\is_array($child)) { |
|
| 63 | + if (!\is_array($child)){ |
|
| 64 | 64 | throw new InvalidArgumentException( |
| 65 | 65 | \vsprintf('Distribution driver config `%s` must be an array, but %s given', [ |
| 66 | 66 | $name, |
@@ -77,9 +77,9 @@ discard block |
||
| 77 | 77 | { |
| 78 | 78 | $default = $config['default'] ?? null; |
| 79 | 79 | |
| 80 | - if ($default !== null) { |
|
| 80 | + if ($default !== null){ |
|
| 81 | 81 | // Validate config |
| 82 | - if (!\is_string($default)) { |
|
| 82 | + if (!\is_string($default)){ |
|
| 83 | 83 | throw new InvalidArgumentException( |
| 84 | 84 | \vsprintf('Distribution config default driver must be a string, but %s given', [ |
| 85 | 85 | \get_debug_type($default), |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | |
| 94 | 94 | private function createResolver(string $name, array $config): UriResolverInterface |
| 95 | 95 | { |
| 96 | - if (!isset($config['type']) || !\is_string($config['type'])) { |
|
| 96 | + if (!isset($config['type']) || !\is_string($config['type'])){ |
|
| 97 | 97 | throw $this->invalidConfigKey($name, 'type', 'string'); |
| 98 | 98 | } |
| 99 | 99 | |
@@ -107,17 +107,17 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | private function createCustomResolver(string $type, string $name, array $config): UriResolverInterface |
| 109 | 109 | { |
| 110 | - if (!\is_subclass_of($type, UriResolverInterface::class, true)) { |
|
| 110 | + if (!\is_subclass_of($type, UriResolverInterface::class, true)){ |
|
| 111 | 111 | throw $this->invalidConfigKey($name, 'type', UriResolverInterface::class); |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - if (isset($config['options']) && !\is_array($config['options'])) { |
|
| 114 | + if (isset($config['options']) && !\is_array($config['options'])){ |
|
| 115 | 115 | throw $this->invalidConfigKey($name, 'options', 'array'); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - try { |
|
| 118 | + try{ |
|
| 119 | 119 | return new $type(...\array_values($config['options'] ?? [])); |
| 120 | - } catch (\Throwable $e) { |
|
| 120 | + }catch (\Throwable $e){ |
|
| 121 | 121 | $message = 'An error occurred while resolver `%s` initializing: %s'; |
| 122 | 122 | throw new InvalidArgumentException(\sprintf($message, $name, $e->getMessage()), 0, $e); |
| 123 | 123 | } |
@@ -126,36 +126,36 @@ discard block |
||
| 126 | 126 | private function createS3Resolver(string $name, array $config): UriResolverInterface |
| 127 | 127 | { |
| 128 | 128 | // Required config options |
| 129 | - if (!isset($config['region']) || !\is_string($config['region'])) { |
|
| 129 | + if (!isset($config['region']) || !\is_string($config['region'])){ |
|
| 130 | 130 | throw $this->invalidConfigKey($name, 'region', 'string'); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - if (!isset($config['key']) || !\is_string($config['key'])) { |
|
| 133 | + if (!isset($config['key']) || !\is_string($config['key'])){ |
|
| 134 | 134 | throw $this->invalidConfigKey($name, 'key', 'string'); |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - if (!isset($config['secret']) || !\is_string($config['secret'])) { |
|
| 137 | + if (!isset($config['secret']) || !\is_string($config['secret'])){ |
|
| 138 | 138 | throw $this->invalidConfigKey($name, 'secret', 'string'); |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - if (!isset($config['bucket']) || !\is_string($config['bucket'])) { |
|
| 141 | + if (!isset($config['bucket']) || !\is_string($config['bucket'])){ |
|
| 142 | 142 | throw $this->invalidConfigKey($name, 'bucket', 'string'); |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | // Optional config options |
| 146 | - if (!\is_string($config['prefix'] ?? '')) { |
|
| 146 | + if (!\is_string($config['prefix'] ?? '')){ |
|
| 147 | 147 | throw $this->invalidConfigKey($name, 'prefix', 'string or null'); |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - if (!\is_string($config['version'] ?? '')) { |
|
| 150 | + if (!\is_string($config['version'] ?? '')){ |
|
| 151 | 151 | throw $this->invalidConfigKey($name, 'version', 'string or null'); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - if (!\is_string($config['token'] ?? '')) { |
|
| 154 | + if (!\is_string($config['token'] ?? '')){ |
|
| 155 | 155 | throw $this->invalidConfigKey($name, 'token', 'string or null'); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - if (!\is_int($config['expires'] ?? 0)) { |
|
| 158 | + if (!\is_int($config['expires'] ?? 0)){ |
|
| 159 | 159 | throw $this->invalidConfigKey($name, 'expires', 'positive int (unix timestamp)'); |
| 160 | 160 | } |
| 161 | 161 | |
@@ -180,19 +180,19 @@ discard block |
||
| 180 | 180 | |
| 181 | 181 | private function createCloudFrontResolver(string $name, array $config): UriResolverInterface |
| 182 | 182 | { |
| 183 | - if (!isset($config['key']) || !\is_string($config['key'])) { |
|
| 183 | + if (!isset($config['key']) || !\is_string($config['key'])){ |
|
| 184 | 184 | throw $this->invalidConfigKey($name, 'key', 'string'); |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - if (!isset($config['private']) || !\is_string($config['private'])) { |
|
| 187 | + if (!isset($config['private']) || !\is_string($config['private'])){ |
|
| 188 | 188 | throw $this->invalidConfigKey($name, 'private', 'string value or path to key file'); |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - if (!isset($config['domain']) || !\is_string($config['domain'])) { |
|
| 191 | + if (!isset($config['domain']) || !\is_string($config['domain'])){ |
|
| 192 | 192 | throw $this->invalidConfigKey($name, 'domain', 'string'); |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - if (!\is_string($config['prefix'] ?? '')) { |
|
| 195 | + if (!\is_string($config['prefix'] ?? '')){ |
|
| 196 | 196 | throw $this->invalidConfigKey($name, 'prefix', 'string or null'); |
| 197 | 197 | } |
| 198 | 198 | |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | |
| 207 | 207 | private function createStaticResolver(string $name, array $config): UriResolverInterface |
| 208 | 208 | { |
| 209 | - if (!isset($config['uri']) || !\is_string($config['uri'])) { |
|
| 209 | + if (!isset($config['uri']) || !\is_string($config['uri'])){ |
|
| 210 | 210 | throw $this->invalidConfigKey($name, 'uri', 'string'); |
| 211 | 211 | } |
| 212 | 212 | |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | |
| 216 | 216 | private function createUri(string $name, string $uri, array $config): UriInterface |
| 217 | 217 | { |
| 218 | - if (!\is_string($config['factory'] ?? '')) { |
|
| 218 | + if (!\is_string($config['factory'] ?? '')){ |
|
| 219 | 219 | throw $this->invalidConfigKey($name, 'factory', 'string (PSR-7 uri factory implementation)'); |
| 220 | 220 | } |
| 221 | 221 | |
@@ -51,8 +51,10 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | private function bootResolvers(array $config): void |
| 53 | 53 | { |
| 54 | - foreach ($config['resolvers'] ?? [] as $name => $child) { |
|
| 55 | - if (!\is_string($name)) { |
|
| 54 | + foreach ($config['resolvers'] ?? [] as $name => $child) |
|
| 55 | + { |
|
| 56 | + if (!\is_string($name)) |
|
| 57 | + { |
|
| 56 | 58 | throw new InvalidArgumentException( |
| 57 | 59 | \vsprintf('Distribution driver config key must be a string, but %s given', [ |
| 58 | 60 | \get_debug_type($child), |
@@ -60,7 +62,8 @@ discard block |
||
| 60 | 62 | ); |
| 61 | 63 | } |
| 62 | 64 | |
| 63 | - if (!\is_array($child)) { |
|
| 65 | + if (!\is_array($child)) |
|
| 66 | + { |
|
| 64 | 67 | throw new InvalidArgumentException( |
| 65 | 68 | \vsprintf('Distribution driver config `%s` must be an array, but %s given', [ |
| 66 | 69 | $name, |
@@ -77,9 +80,11 @@ discard block |
||
| 77 | 80 | { |
| 78 | 81 | $default = $config['default'] ?? null; |
| 79 | 82 | |
| 80 | - if ($default !== null) { |
|
| 83 | + if ($default !== null) |
|
| 84 | + { |
|
| 81 | 85 | // Validate config |
| 82 | - if (!\is_string($default)) { |
|
| 86 | + if (!\is_string($default)) |
|
| 87 | + { |
|
| 83 | 88 | throw new InvalidArgumentException( |
| 84 | 89 | \vsprintf('Distribution config default driver must be a string, but %s given', [ |
| 85 | 90 | \get_debug_type($default), |
@@ -93,7 +98,8 @@ discard block |
||
| 93 | 98 | |
| 94 | 99 | private function createResolver(string $name, array $config): UriResolverInterface |
| 95 | 100 | { |
| 96 | - if (!isset($config['type']) || !\is_string($config['type'])) { |
|
| 101 | + if (!isset($config['type']) || !\is_string($config['type'])) |
|
| 102 | + { |
|
| 97 | 103 | throw $this->invalidConfigKey($name, 'type', 'string'); |
| 98 | 104 | } |
| 99 | 105 | |
@@ -107,17 +113,22 @@ discard block |
||
| 107 | 113 | |
| 108 | 114 | private function createCustomResolver(string $type, string $name, array $config): UriResolverInterface |
| 109 | 115 | { |
| 110 | - if (!\is_subclass_of($type, UriResolverInterface::class, true)) { |
|
| 116 | + if (!\is_subclass_of($type, UriResolverInterface::class, true)) |
|
| 117 | + { |
|
| 111 | 118 | throw $this->invalidConfigKey($name, 'type', UriResolverInterface::class); |
| 112 | 119 | } |
| 113 | 120 | |
| 114 | - if (isset($config['options']) && !\is_array($config['options'])) { |
|
| 121 | + if (isset($config['options']) && !\is_array($config['options'])) |
|
| 122 | + { |
|
| 115 | 123 | throw $this->invalidConfigKey($name, 'options', 'array'); |
| 116 | 124 | } |
| 117 | 125 | |
| 118 | - try { |
|
| 126 | + try |
|
| 127 | + { |
|
| 119 | 128 | return new $type(...\array_values($config['options'] ?? [])); |
| 120 | - } catch (\Throwable $e) { |
|
| 129 | + } |
|
| 130 | + catch (\Throwable $e) |
|
| 131 | + { |
|
| 121 | 132 | $message = 'An error occurred while resolver `%s` initializing: %s'; |
| 122 | 133 | throw new InvalidArgumentException(\sprintf($message, $name, $e->getMessage()), 0, $e); |
| 123 | 134 | } |
@@ -126,36 +137,44 @@ discard block |
||
| 126 | 137 | private function createS3Resolver(string $name, array $config): UriResolverInterface |
| 127 | 138 | { |
| 128 | 139 | // Required config options |
| 129 | - if (!isset($config['region']) || !\is_string($config['region'])) { |
|
| 140 | + if (!isset($config['region']) || !\is_string($config['region'])) |
|
| 141 | + { |
|
| 130 | 142 | throw $this->invalidConfigKey($name, 'region', 'string'); |
| 131 | 143 | } |
| 132 | 144 | |
| 133 | - if (!isset($config['key']) || !\is_string($config['key'])) { |
|
| 145 | + if (!isset($config['key']) || !\is_string($config['key'])) |
|
| 146 | + { |
|
| 134 | 147 | throw $this->invalidConfigKey($name, 'key', 'string'); |
| 135 | 148 | } |
| 136 | 149 | |
| 137 | - if (!isset($config['secret']) || !\is_string($config['secret'])) { |
|
| 150 | + if (!isset($config['secret']) || !\is_string($config['secret'])) |
|
| 151 | + { |
|
| 138 | 152 | throw $this->invalidConfigKey($name, 'secret', 'string'); |
| 139 | 153 | } |
| 140 | 154 | |
| 141 | - if (!isset($config['bucket']) || !\is_string($config['bucket'])) { |
|
| 155 | + if (!isset($config['bucket']) || !\is_string($config['bucket'])) |
|
| 156 | + { |
|
| 142 | 157 | throw $this->invalidConfigKey($name, 'bucket', 'string'); |
| 143 | 158 | } |
| 144 | 159 | |
| 145 | 160 | // Optional config options |
| 146 | - if (!\is_string($config['prefix'] ?? '')) { |
|
| 161 | + if (!\is_string($config['prefix'] ?? '')) |
|
| 162 | + { |
|
| 147 | 163 | throw $this->invalidConfigKey($name, 'prefix', 'string or null'); |
| 148 | 164 | } |
| 149 | 165 | |
| 150 | - if (!\is_string($config['version'] ?? '')) { |
|
| 166 | + if (!\is_string($config['version'] ?? '')) |
|
| 167 | + { |
|
| 151 | 168 | throw $this->invalidConfigKey($name, 'version', 'string or null'); |
| 152 | 169 | } |
| 153 | 170 | |
| 154 | - if (!\is_string($config['token'] ?? '')) { |
|
| 171 | + if (!\is_string($config['token'] ?? '')) |
|
| 172 | + { |
|
| 155 | 173 | throw $this->invalidConfigKey($name, 'token', 'string or null'); |
| 156 | 174 | } |
| 157 | 175 | |
| 158 | - if (!\is_int($config['expires'] ?? 0)) { |
|
| 176 | + if (!\is_int($config['expires'] ?? 0)) |
|
| 177 | + { |
|
| 159 | 178 | throw $this->invalidConfigKey($name, 'expires', 'positive int (unix timestamp)'); |
| 160 | 179 | } |
| 161 | 180 | |
@@ -180,19 +199,23 @@ discard block |
||
| 180 | 199 | |
| 181 | 200 | private function createCloudFrontResolver(string $name, array $config): UriResolverInterface |
| 182 | 201 | { |
| 183 | - if (!isset($config['key']) || !\is_string($config['key'])) { |
|
| 202 | + if (!isset($config['key']) || !\is_string($config['key'])) |
|
| 203 | + { |
|
| 184 | 204 | throw $this->invalidConfigKey($name, 'key', 'string'); |
| 185 | 205 | } |
| 186 | 206 | |
| 187 | - if (!isset($config['private']) || !\is_string($config['private'])) { |
|
| 207 | + if (!isset($config['private']) || !\is_string($config['private'])) |
|
| 208 | + { |
|
| 188 | 209 | throw $this->invalidConfigKey($name, 'private', 'string value or path to key file'); |
| 189 | 210 | } |
| 190 | 211 | |
| 191 | - if (!isset($config['domain']) || !\is_string($config['domain'])) { |
|
| 212 | + if (!isset($config['domain']) || !\is_string($config['domain'])) |
|
| 213 | + { |
|
| 192 | 214 | throw $this->invalidConfigKey($name, 'domain', 'string'); |
| 193 | 215 | } |
| 194 | 216 | |
| 195 | - if (!\is_string($config['prefix'] ?? '')) { |
|
| 217 | + if (!\is_string($config['prefix'] ?? '')) |
|
| 218 | + { |
|
| 196 | 219 | throw $this->invalidConfigKey($name, 'prefix', 'string or null'); |
| 197 | 220 | } |
| 198 | 221 | |
@@ -206,7 +229,8 @@ discard block |
||
| 206 | 229 | |
| 207 | 230 | private function createStaticResolver(string $name, array $config): UriResolverInterface |
| 208 | 231 | { |
| 209 | - if (!isset($config['uri']) || !\is_string($config['uri'])) { |
|
| 232 | + if (!isset($config['uri']) || !\is_string($config['uri'])) |
|
| 233 | + { |
|
| 210 | 234 | throw $this->invalidConfigKey($name, 'uri', 'string'); |
| 211 | 235 | } |
| 212 | 236 | |
@@ -215,7 +239,8 @@ discard block |
||
| 215 | 239 | |
| 216 | 240 | private function createUri(string $name, string $uri, array $config): UriInterface |
| 217 | 241 | { |
| 218 | - if (!\is_string($config['factory'] ?? '')) { |
|
| 242 | + if (!\is_string($config['factory'] ?? '')) |
|
| 243 | + { |
|
| 219 | 244 | throw $this->invalidConfigKey($name, 'factory', 'string (PSR-7 uri factory implementation)'); |
| 220 | 245 | } |
| 221 | 246 | |