@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | protected CacheInterface $storage, |
| 26 | 26 | protected ?EventDispatcherInterface $dispatcher = null, |
| 27 | 27 | protected ?string $prefix = null, |
| 28 | - ) {} |
|
| 28 | + ){} |
|
| 29 | 29 | |
| 30 | 30 | public function get(string $key, mixed $default = null): mixed |
| 31 | 31 | { |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | $value = $this->storage->get($key); |
| 37 | 37 | |
| 38 | - if ($value === null) { |
|
| 38 | + if ($value === null){ |
|
| 39 | 39 | $this->dispatcher?->dispatch(new CacheMissed($key)); |
| 40 | 40 | |
| 41 | 41 | return $default; |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | return $value; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - public function set(string $key, mixed $value, \DateInterval|int|null $ttl = null): bool |
|
| 49 | + public function set(string $key, mixed $value, \DateInterval | int | null $ttl = null): bool |
|
| 50 | 50 | { |
| 51 | 51 | $key = $this->resolveKey($key); |
| 52 | 52 | |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | { |
| 90 | 90 | $array = []; |
| 91 | 91 | // Resolve keys and dispatch events |
| 92 | - foreach ($keys as $key) { |
|
| 92 | + foreach ($keys as $key){ |
|
| 93 | 93 | $key = $this->resolveKey($key); |
| 94 | 94 | $this->dispatcher?->dispatch(new CacheRetrieving($key)); |
| 95 | 95 | // Fill resulting array with default values |
@@ -99,16 +99,16 @@ discard block |
||
| 99 | 99 | // If no dispatcher is set, we can skip the loop with events |
| 100 | 100 | // to save some CPU cycles |
| 101 | 101 | $keys = \array_keys($array); |
| 102 | - if (!$this->dispatcher instanceof \Psr\EventDispatcher\EventDispatcherInterface) { |
|
| 102 | + if (!$this->dispatcher instanceof \Psr\EventDispatcher\EventDispatcherInterface){ |
|
| 103 | 103 | return $this->storage->getMultiple($keys, $default); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $result = $this->storage->getMultiple($keys); |
| 107 | 107 | |
| 108 | - foreach ($result as $key => $value) { |
|
| 109 | - if ($value === null) { |
|
| 108 | + foreach ($result as $key => $value){ |
|
| 109 | + if ($value === null){ |
|
| 110 | 110 | $this->dispatcher->dispatch(new CacheMissed($key)); |
| 111 | - } else { |
|
| 111 | + }else{ |
|
| 112 | 112 | // Replace default value with actual value in the resulting array |
| 113 | 113 | $array[$key] = $value; |
| 114 | 114 | $this->dispatcher->dispatch(new CacheHit($key, $value)); |
@@ -118,12 +118,12 @@ discard block |
||
| 118 | 118 | return $array; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - public function setMultiple(iterable $values, \DateInterval|int|null $ttl = null): bool |
|
| 121 | + public function setMultiple(iterable $values, \DateInterval | int | null $ttl = null): bool |
|
| 122 | 122 | { |
| 123 | 123 | $dispatcher = $this->dispatcher; |
| 124 | 124 | $array = []; |
| 125 | 125 | // Resolve keys and dispatch events |
| 126 | - foreach ($values as $key => $value) { |
|
| 126 | + foreach ($values as $key => $value){ |
|
| 127 | 127 | $key = $this->resolveKey($key); |
| 128 | 128 | $dispatcher?->dispatch(new KeyWriting($key, $value)); |
| 129 | 129 | $array[$key] = $value; |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | |
| 149 | 149 | $array = []; |
| 150 | 150 | // Resolve keys and dispatch events |
| 151 | - foreach ($keys as $key) { |
|
| 151 | + foreach ($keys as $key){ |
|
| 152 | 152 | $key = $this->resolveKey($key); |
| 153 | 153 | $dispatcher?->dispatch(new KeyDeleting($key)); |
| 154 | 154 | $array[] = $key; |
@@ -179,6 +179,6 @@ discard block |
||
| 179 | 179 | |
| 180 | 180 | private function resolveKey(string $key): string |
| 181 | 181 | { |
| 182 | - return $this->prefix . $key; |
|
| 182 | + return $this->prefix.$key; |
|
| 183 | 183 | } |
| 184 | 184 | } |
@@ -25,7 +25,8 @@ discard block |
||
| 25 | 25 | protected CacheInterface $storage, |
| 26 | 26 | protected ?EventDispatcherInterface $dispatcher = null, |
| 27 | 27 | protected ?string $prefix = null, |
| 28 | - ) {} |
|
| 28 | + ) { |
|
| 29 | +} |
|
| 29 | 30 | |
| 30 | 31 | public function get(string $key, mixed $default = null): mixed |
| 31 | 32 | { |
@@ -35,7 +36,8 @@ discard block |
||
| 35 | 36 | |
| 36 | 37 | $value = $this->storage->get($key); |
| 37 | 38 | |
| 38 | - if ($value === null) { |
|
| 39 | + if ($value === null) |
|
| 40 | + { |
|
| 39 | 41 | $this->dispatcher?->dispatch(new CacheMissed($key)); |
| 40 | 42 | |
| 41 | 43 | return $default; |
@@ -89,7 +91,8 @@ discard block |
||
| 89 | 91 | { |
| 90 | 92 | $array = []; |
| 91 | 93 | // Resolve keys and dispatch events |
| 92 | - foreach ($keys as $key) { |
|
| 94 | + foreach ($keys as $key) |
|
| 95 | + { |
|
| 93 | 96 | $key = $this->resolveKey($key); |
| 94 | 97 | $this->dispatcher?->dispatch(new CacheRetrieving($key)); |
| 95 | 98 | // Fill resulting array with default values |
@@ -99,16 +102,21 @@ discard block |
||
| 99 | 102 | // If no dispatcher is set, we can skip the loop with events |
| 100 | 103 | // to save some CPU cycles |
| 101 | 104 | $keys = \array_keys($array); |
| 102 | - if (!$this->dispatcher instanceof \Psr\EventDispatcher\EventDispatcherInterface) { |
|
| 105 | + if (!$this->dispatcher instanceof \Psr\EventDispatcher\EventDispatcherInterface) |
|
| 106 | + { |
|
| 103 | 107 | return $this->storage->getMultiple($keys, $default); |
| 104 | 108 | } |
| 105 | 109 | |
| 106 | 110 | $result = $this->storage->getMultiple($keys); |
| 107 | 111 | |
| 108 | - foreach ($result as $key => $value) { |
|
| 109 | - if ($value === null) { |
|
| 112 | + foreach ($result as $key => $value) |
|
| 113 | + { |
|
| 114 | + if ($value === null) |
|
| 115 | + { |
|
| 110 | 116 | $this->dispatcher->dispatch(new CacheMissed($key)); |
| 111 | - } else { |
|
| 117 | + } |
|
| 118 | + else |
|
| 119 | + { |
|
| 112 | 120 | // Replace default value with actual value in the resulting array |
| 113 | 121 | $array[$key] = $value; |
| 114 | 122 | $this->dispatcher->dispatch(new CacheHit($key, $value)); |
@@ -123,7 +131,8 @@ discard block |
||
| 123 | 131 | $dispatcher = $this->dispatcher; |
| 124 | 132 | $array = []; |
| 125 | 133 | // Resolve keys and dispatch events |
| 126 | - foreach ($values as $key => $value) { |
|
| 134 | + foreach ($values as $key => $value) |
|
| 135 | + { |
|
| 127 | 136 | $key = $this->resolveKey($key); |
| 128 | 137 | $dispatcher?->dispatch(new KeyWriting($key, $value)); |
| 129 | 138 | $array[$key] = $value; |
@@ -148,7 +157,8 @@ discard block |
||
| 148 | 157 | |
| 149 | 158 | $array = []; |
| 150 | 159 | // Resolve keys and dispatch events |
| 151 | - foreach ($keys as $key) { |
|
| 160 | + foreach ($keys as $key) |
|
| 161 | + { |
|
| 152 | 162 | $key = $this->resolveKey($key); |
| 153 | 163 | $dispatcher?->dispatch(new KeyDeleting($key)); |
| 154 | 164 | $array[] = $key; |
@@ -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,12 +39,12 @@ 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 | |
| 46 | 46 | //Automatically registering |
| 47 | - if (!$this->catalogue->has($domain, $string)) { |
|
| 47 | + if (!$this->catalogue->has($domain, $string)){ |
|
| 48 | 48 | $this->catalogue->set($domain, $string, $string); |
| 49 | 49 | } |
| 50 | 50 | |
@@ -60,9 +60,9 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | public function indexClasses(ScopedClassesInterface $locator): void |
| 62 | 62 | { |
| 63 | - foreach ($locator->getScopedClasses('translations', TranslatorTrait::class) as $class) { |
|
| 63 | + foreach ($locator->getScopedClasses('translations', TranslatorTrait::class) as $class){ |
|
| 64 | 64 | $strings = $this->fetchMessages($class, true); |
| 65 | - foreach ($strings as $string) { |
|
| 65 | + foreach ($strings as $string){ |
|
| 66 | 66 | $this->registerMessage($class->getName(), $string); |
| 67 | 67 | } |
| 68 | 68 | } |
@@ -94,8 +94,8 @@ discard block |
||
| 94 | 94 | */ |
| 95 | 95 | private function registerInvocations(array $invocations): void |
| 96 | 96 | { |
| 97 | - foreach ($invocations as $invocation) { |
|
| 98 | - if ($invocation->getArgument(0)->getType() != ReflectionArgument::STRING) { |
|
| 97 | + foreach ($invocations as $invocation){ |
|
| 98 | + if ($invocation->getArgument(0)->getType() != ReflectionArgument::STRING){ |
|
| 99 | 99 | //We can only index invocations with constant string arguments |
| 100 | 100 | continue; |
| 101 | 101 | } |
@@ -114,20 +114,20 @@ discard block |
||
| 114 | 114 | { |
| 115 | 115 | $target = $reflection->getDefaultProperties() + $reflection->getConstants(); |
| 116 | 116 | |
| 117 | - foreach ($reflection->getProperties() as $property) { |
|
| 118 | - if (\is_string($property->getDocComment()) && \strpos($property->getDocComment(), '@do-not-index')) { |
|
| 117 | + foreach ($reflection->getProperties() as $property){ |
|
| 118 | + if (\is_string($property->getDocComment()) && \strpos($property->getDocComment(), '@do-not-index')){ |
|
| 119 | 119 | unset($target[$property->getName()]); |
| 120 | 120 | } |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | $strings = []; |
| 124 | 124 | \array_walk_recursive($target, function ($value) use (&$strings): void { |
| 125 | - if (\is_string($value) && Translator::isMessage($value)) { |
|
| 125 | + if (\is_string($value) && Translator::isMessage($value)){ |
|
| 126 | 126 | $strings[] = $this->prepareMessage($value); |
| 127 | 127 | } |
| 128 | 128 | }); |
| 129 | 129 | |
| 130 | - if ($inherit && $reflection->getParentClass()) { |
|
| 130 | + if ($inherit && $reflection->getParentClass()){ |
|
| 131 | 131 | //Joining strings data with parent class values (inheritance ON) - resolved into same |
| 132 | 132 | //domain on export |
| 133 | 133 | $strings = \array_merge( |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | //Translation using default bundle |
| 148 | 148 | $domain = $this->config->getDefaultDomain(); |
| 149 | 149 | |
| 150 | - if ($invocation->getName() === 'say') { |
|
| 150 | + if ($invocation->getName() === 'say'){ |
|
| 151 | 151 | //Let's try to confirm domain |
| 152 | 152 | $domain = $this->config->resolveDomain($invocation->getClass()); |
| 153 | 153 | } |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | default => null |
| 160 | 160 | }; |
| 161 | 161 | |
| 162 | - if ($argument instanceof \Spiral\Tokenizer\Reflection\ReflectionArgument && $argument->getType() === ReflectionArgument::STRING) { |
|
| 162 | + if ($argument instanceof \Spiral\Tokenizer\Reflection\ReflectionArgument && $argument->getType() === ReflectionArgument::STRING){ |
|
| 163 | 163 | //Domain specified in arguments |
| 164 | 164 | $domain = $this->config->resolveDomain($argument->stringValue()); |
| 165 | 165 | } |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | */ |
| 173 | 173 | private function prepareMessage(string $string): string |
| 174 | 174 | { |
| 175 | - if (Translator::isMessage($string)) { |
|
| 175 | + if (Translator::isMessage($string)){ |
|
| 176 | 176 | $string = \substr($string, 2, -2); |
| 177 | 177 | } |
| 178 | 178 | |
@@ -39,12 +39,14 @@ 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 | |
| 46 | 47 | //Automatically registering |
| 47 | - if (!$this->catalogue->has($domain, $string)) { |
|
| 48 | + if (!$this->catalogue->has($domain, $string)) |
|
| 49 | + { |
|
| 48 | 50 | $this->catalogue->set($domain, $string, $string); |
| 49 | 51 | } |
| 50 | 52 | |
@@ -60,9 +62,11 @@ discard block |
||
| 60 | 62 | */ |
| 61 | 63 | public function indexClasses(ScopedClassesInterface $locator): void |
| 62 | 64 | { |
| 63 | - foreach ($locator->getScopedClasses('translations', TranslatorTrait::class) as $class) { |
|
| 65 | + foreach ($locator->getScopedClasses('translations', TranslatorTrait::class) as $class) |
|
| 66 | + { |
|
| 64 | 67 | $strings = $this->fetchMessages($class, true); |
| 65 | - foreach ($strings as $string) { |
|
| 68 | + foreach ($strings as $string) |
|
| 69 | + { |
|
| 66 | 70 | $this->registerMessage($class->getName(), $string); |
| 67 | 71 | } |
| 68 | 72 | } |
@@ -94,8 +98,10 @@ discard block |
||
| 94 | 98 | */ |
| 95 | 99 | private function registerInvocations(array $invocations): void |
| 96 | 100 | { |
| 97 | - foreach ($invocations as $invocation) { |
|
| 98 | - if ($invocation->getArgument(0)->getType() != ReflectionArgument::STRING) { |
|
| 101 | + foreach ($invocations as $invocation) |
|
| 102 | + { |
|
| 103 | + if ($invocation->getArgument(0)->getType() != ReflectionArgument::STRING) |
|
| 104 | + { |
|
| 99 | 105 | //We can only index invocations with constant string arguments |
| 100 | 106 | continue; |
| 101 | 107 | } |
@@ -114,20 +120,24 @@ discard block |
||
| 114 | 120 | { |
| 115 | 121 | $target = $reflection->getDefaultProperties() + $reflection->getConstants(); |
| 116 | 122 | |
| 117 | - foreach ($reflection->getProperties() as $property) { |
|
| 118 | - if (\is_string($property->getDocComment()) && \strpos($property->getDocComment(), '@do-not-index')) { |
|
| 123 | + foreach ($reflection->getProperties() as $property) |
|
| 124 | + { |
|
| 125 | + if (\is_string($property->getDocComment()) && \strpos($property->getDocComment(), '@do-not-index')) |
|
| 126 | + { |
|
| 119 | 127 | unset($target[$property->getName()]); |
| 120 | 128 | } |
| 121 | 129 | } |
| 122 | 130 | |
| 123 | 131 | $strings = []; |
| 124 | 132 | \array_walk_recursive($target, function ($value) use (&$strings): void { |
| 125 | - if (\is_string($value) && Translator::isMessage($value)) { |
|
| 133 | + if (\is_string($value) && Translator::isMessage($value)) |
|
| 134 | + { |
|
| 126 | 135 | $strings[] = $this->prepareMessage($value); |
| 127 | 136 | } |
| 128 | 137 | }); |
| 129 | 138 | |
| 130 | - if ($inherit && $reflection->getParentClass()) { |
|
| 139 | + if ($inherit && $reflection->getParentClass()) |
|
| 140 | + { |
|
| 131 | 141 | //Joining strings data with parent class values (inheritance ON) - resolved into same |
| 132 | 142 | //domain on export |
| 133 | 143 | $strings = \array_merge( |
@@ -147,7 +157,8 @@ discard block |
||
| 147 | 157 | //Translation using default bundle |
| 148 | 158 | $domain = $this->config->getDefaultDomain(); |
| 149 | 159 | |
| 150 | - if ($invocation->getName() === 'say') { |
|
| 160 | + if ($invocation->getName() === 'say') |
|
| 161 | + { |
|
| 151 | 162 | //Let's try to confirm domain |
| 152 | 163 | $domain = $this->config->resolveDomain($invocation->getClass()); |
| 153 | 164 | } |
@@ -159,7 +170,8 @@ discard block |
||
| 159 | 170 | default => null |
| 160 | 171 | }; |
| 161 | 172 | |
| 162 | - if ($argument instanceof \Spiral\Tokenizer\Reflection\ReflectionArgument && $argument->getType() === ReflectionArgument::STRING) { |
|
| 173 | + if ($argument instanceof \Spiral\Tokenizer\Reflection\ReflectionArgument && $argument->getType() === ReflectionArgument::STRING) |
|
| 174 | + { |
|
| 163 | 175 | //Domain specified in arguments |
| 164 | 176 | $domain = $this->config->resolveDomain($argument->stringValue()); |
| 165 | 177 | } |
@@ -172,7 +184,8 @@ discard block |
||
| 172 | 184 | */ |
| 173 | 185 | private function prepareMessage(string $string): string |
| 174 | 186 | { |
| 175 | - if (Translator::isMessage($string)) { |
|
| 187 | + if (Translator::isMessage($string)) |
|
| 188 | + { |
|
| 176 | 189 | $string = \substr($string, 2, -2); |
| 177 | 190 | } |
| 178 | 191 | |
@@ -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 instanceof \Psr\Container\ContainerInterface || !$container->has(TranslatorInterface::class)) { |
|
| 25 | + if (!$container instanceof \Psr\Container\ContainerInterface || !$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 (!$container instanceof \Psr\Container\ContainerInterface || !$container->has(TranslatorInterface::class)) { |
|
| 54 | + if (!$container instanceof \Psr\Container\ContainerInterface || !$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 instanceof \Psr\Container\ContainerInterface || !$container->has(TranslatorInterface::class)) { |
|
| 26 | + if (!$container instanceof \Psr\Container\ContainerInterface || !$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 (!$container instanceof \Psr\Container\ContainerInterface || !$container->has(TranslatorInterface::class)) { |
|
| 57 | + if (!$container instanceof \Psr\Container\ContainerInterface || !$container->has(TranslatorInterface::class)) |
|
| 58 | + { |
|
| 55 | 59 | throw new ScopeException( |
| 56 | 60 | '`TranslatorInterface` binding is missing or container scope is not set' |
| 57 | 61 | ); |
@@ -32,13 +32,13 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | protected function say(string $string, array $options = [], ?string $bundle = null): string |
| 34 | 34 | { |
| 35 | - if (Translator::isMessage($string)) { |
|
| 35 | + if (Translator::isMessage($string)){ |
|
| 36 | 36 | //Cut [[ and ]] |
| 37 | 37 | $string = \substr($string, 2, -2); |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | $container = ContainerScope::getContainer(); |
| 41 | - if (!$container instanceof \Psr\Container\ContainerInterface || !$container->has(TranslatorInterface::class)) { |
|
| 41 | + if (!$container instanceof \Psr\Container\ContainerInterface || !$container->has(TranslatorInterface::class)){ |
|
| 42 | 42 | return Translator::interpolate($string, $options); |
| 43 | 43 | } |
| 44 | 44 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | $translator = $container->get(TranslatorInterface::class); |
| 49 | 49 | |
| 50 | - if (\is_null($bundle)) { |
|
| 50 | + if (\is_null($bundle)){ |
|
| 51 | 51 | $bundle = $translator->getDomain(static::class); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -32,13 +32,15 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | protected function say(string $string, array $options = [], ?string $bundle = null): string |
| 34 | 34 | { |
| 35 | - if (Translator::isMessage($string)) { |
|
| 35 | + if (Translator::isMessage($string)) |
|
| 36 | + { |
|
| 36 | 37 | //Cut [[ and ]] |
| 37 | 38 | $string = \substr($string, 2, -2); |
| 38 | 39 | } |
| 39 | 40 | |
| 40 | 41 | $container = ContainerScope::getContainer(); |
| 41 | - if (!$container instanceof \Psr\Container\ContainerInterface || !$container->has(TranslatorInterface::class)) { |
|
| 42 | + if (!$container instanceof \Psr\Container\ContainerInterface || !$container->has(TranslatorInterface::class)) |
|
| 43 | + { |
|
| 42 | 44 | return Translator::interpolate($string, $options); |
| 43 | 45 | } |
| 44 | 46 | |
@@ -47,7 +49,8 @@ discard block |
||
| 47 | 49 | */ |
| 48 | 50 | $translator = $container->get(TranslatorInterface::class); |
| 49 | 51 | |
| 50 | - if (\is_null($bundle)) { |
|
| 52 | + if (\is_null($bundle)) |
|
| 53 | + { |
|
| 51 | 54 | $bundle = $translator->getDomain(static::class); |
| 52 | 55 | } |
| 53 | 56 | |
@@ -22,20 +22,20 @@ discard block |
||
| 22 | 22 | private readonly ResponseFactoryInterface $responseFactory, |
| 23 | 23 | private readonly ?string $authorizationPath = null, |
| 24 | 24 | private readonly ?EventDispatcherInterface $dispatcher = null |
| 25 | - ) { |
|
| 25 | + ){ |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | public function process( |
| 29 | 29 | ServerRequestInterface $request, |
| 30 | 30 | RequestHandlerInterface $handler |
| 31 | 31 | ): ResponseInterface { |
| 32 | - if ($request->getUri()->getPath() !== $this->authorizationPath) { |
|
| 32 | + if ($request->getUri()->getPath() !== $this->authorizationPath){ |
|
| 33 | 33 | return $handler->handle($request); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - if ($this->broadcast instanceof GuardInterface) { |
|
| 36 | + if ($this->broadcast instanceof GuardInterface){ |
|
| 37 | 37 | $status = $this->broadcast->authorize($request); |
| 38 | - } else { |
|
| 38 | + }else{ |
|
| 39 | 39 | $status = new AuthorizationStatus( |
| 40 | 40 | success: true, |
| 41 | 41 | topics: null |
@@ -44,11 +44,11 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | $this->dispatcher?->dispatch(new Authorized($status, $request)); |
| 46 | 46 | |
| 47 | - if ($status->response instanceof \Psr\Http\Message\ResponseInterface) { |
|
| 47 | + if ($status->response instanceof \Psr\Http\Message\ResponseInterface){ |
|
| 48 | 48 | return $status->response; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - if (!$status->success) { |
|
| 51 | + if (!$status->success){ |
|
| 52 | 52 | return $this->responseFactory->createResponse(403); |
| 53 | 53 | } |
| 54 | 54 | |
@@ -29,13 +29,17 @@ discard block |
||
| 29 | 29 | ServerRequestInterface $request, |
| 30 | 30 | RequestHandlerInterface $handler |
| 31 | 31 | ): ResponseInterface { |
| 32 | - if ($request->getUri()->getPath() !== $this->authorizationPath) { |
|
| 32 | + if ($request->getUri()->getPath() !== $this->authorizationPath) |
|
| 33 | + { |
|
| 33 | 34 | return $handler->handle($request); |
| 34 | 35 | } |
| 35 | 36 | |
| 36 | - if ($this->broadcast instanceof GuardInterface) { |
|
| 37 | + if ($this->broadcast instanceof GuardInterface) |
|
| 38 | + { |
|
| 37 | 39 | $status = $this->broadcast->authorize($request); |
| 38 | - } else { |
|
| 40 | + } |
|
| 41 | + else |
|
| 42 | + { |
|
| 39 | 43 | $status = new AuthorizationStatus( |
| 40 | 44 | success: true, |
| 41 | 45 | topics: null |
@@ -44,11 +48,13 @@ discard block |
||
| 44 | 48 | |
| 45 | 49 | $this->dispatcher?->dispatch(new Authorized($status, $request)); |
| 46 | 50 | |
| 47 | - if ($status->response instanceof \Psr\Http\Message\ResponseInterface) { |
|
| 51 | + if ($status->response instanceof \Psr\Http\Message\ResponseInterface) |
|
| 52 | + { |
|
| 48 | 53 | return $status->response; |
| 49 | 54 | } |
| 50 | 55 | |
| 51 | - if (!$status->success) { |
|
| 56 | + if (!$status->success) |
|
| 57 | + { |
|
| 52 | 58 | return $this->responseFactory->createResponse(403); |
| 53 | 59 | } |
| 54 | 60 | |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | ?FilesInterface $files = null, |
| 26 | 26 | private readonly string $defaultNamespace = self::DEFAULT_NAMESPACE, |
| 27 | 27 | private readonly ?EventDispatcherInterface $dispatcher = null, |
| 28 | - ) { |
|
| 28 | + ){ |
|
| 29 | 29 | $this->files = $files ?? new Files(); |
| 30 | 30 | } |
| 31 | 31 | |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | public function getExtension(): ?string |
| 41 | 41 | { |
| 42 | - if ($this->parser instanceof \Spiral\Views\Loader\PathParser) { |
|
| 42 | + if ($this->parser instanceof \Spiral\Views\Loader\PathParser){ |
|
| 43 | 43 | return $this->parser->getExtension(); |
| 44 | 44 | } |
| 45 | 45 | |
@@ -50,24 +50,24 @@ discard block |
||
| 50 | 50 | * @psalm-assert-if-true non-empty-string $filename |
| 51 | 51 | * @psalm-assert-if-true ViewPath $parsed |
| 52 | 52 | */ |
| 53 | - public function exists(string $path, ?string &$filename = null, ?ViewPath &$parsed = null): bool |
|
| 53 | + public function exists(string $path, ?string &$filename = null, ?ViewPath & $parsed = null): bool |
|
| 54 | 54 | { |
| 55 | - if (!$this->parser instanceof \Spiral\Views\Loader\PathParser) { |
|
| 55 | + if (!$this->parser instanceof \Spiral\Views\Loader\PathParser){ |
|
| 56 | 56 | throw new LoaderException('Unable to locate view source, no extension has been associated.'); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | $parsed = $this->parser->parse($path); |
| 60 | - if (!$parsed instanceof \Spiral\Views\Loader\ViewPath) { |
|
| 60 | + if (!$parsed instanceof \Spiral\Views\Loader\ViewPath){ |
|
| 61 | 61 | return false; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - if (!isset($this->namespaces[$parsed->getNamespace()])) { |
|
| 64 | + if (!isset($this->namespaces[$parsed->getNamespace()])){ |
|
| 65 | 65 | return false; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - foreach ((array)$this->namespaces[$parsed->getNamespace()] as $directory) { |
|
| 68 | + foreach ((array)$this->namespaces[$parsed->getNamespace()] as $directory){ |
|
| 69 | 69 | $directory = $this->files->normalizePath($directory, true); |
| 70 | - if ($this->files->exists(\sprintf('%s%s', $directory, $parsed->getBasename()))) { |
|
| 70 | + if ($this->files->exists(\sprintf('%s%s', $directory, $parsed->getBasename()))){ |
|
| 71 | 71 | $filename = \sprintf('%s%s', $directory, $parsed->getBasename()); |
| 72 | 72 | |
| 73 | 73 | return true; |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | |
| 80 | 80 | public function load(string $path): ViewSource |
| 81 | 81 | { |
| 82 | - if (!$this->exists($path, $filename, $parsed)) { |
|
| 82 | + if (!$this->exists($path, $filename, $parsed)){ |
|
| 83 | 83 | $this->dispatcher?->dispatch(new ViewNotFound($path)); |
| 84 | 84 | |
| 85 | 85 | throw new LoaderException(\sprintf('Unable to load view `%s`, file does not exist.', $path)); |
@@ -92,23 +92,23 @@ discard block |
||
| 92 | 92 | ); |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - public function list(?string $namespace = null): array |
|
| 95 | + public function list(?string $namespace = null) : array |
|
| 96 | 96 | { |
| 97 | - if (!$this->parser instanceof \Spiral\Views\Loader\PathParser) { |
|
| 97 | + if (!$this->parser instanceof \Spiral\Views\Loader\PathParser){ |
|
| 98 | 98 | throw new LoaderException('Unable to list view sources, no extension has been associated.'); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | $result = []; |
| 102 | - foreach ($this->namespaces as $ns => $directories) { |
|
| 103 | - if (!empty($namespace) && $namespace != $ns) { |
|
| 102 | + foreach ($this->namespaces as $ns => $directories){ |
|
| 103 | + if (!empty($namespace) && $namespace != $ns){ |
|
| 104 | 104 | continue; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - foreach ((array)$directories as $directory) { |
|
| 107 | + foreach ((array)$directories as $directory){ |
|
| 108 | 108 | $files = $this->files->getFiles($directory); |
| 109 | 109 | |
| 110 | - foreach ($files as $filename) { |
|
| 111 | - if (!$this->parser->match($filename)) { |
|
| 110 | + foreach ($files as $filename){ |
|
| 111 | + if (!$this->parser->match($filename)){ |
|
| 112 | 112 | // does not belong to this loader |
| 113 | 113 | continue; |
| 114 | 114 | } |
@@ -39,7 +39,8 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | public function getExtension(): ?string |
| 41 | 41 | { |
| 42 | - if ($this->parser instanceof \Spiral\Views\Loader\PathParser) { |
|
| 42 | + if ($this->parser instanceof \Spiral\Views\Loader\PathParser) |
|
| 43 | + { |
|
| 43 | 44 | return $this->parser->getExtension(); |
| 44 | 45 | } |
| 45 | 46 | |
@@ -52,22 +53,27 @@ discard block |
||
| 52 | 53 | */ |
| 53 | 54 | public function exists(string $path, ?string &$filename = null, ?ViewPath &$parsed = null): bool |
| 54 | 55 | { |
| 55 | - if (!$this->parser instanceof \Spiral\Views\Loader\PathParser) { |
|
| 56 | + if (!$this->parser instanceof \Spiral\Views\Loader\PathParser) |
|
| 57 | + { |
|
| 56 | 58 | throw new LoaderException('Unable to locate view source, no extension has been associated.'); |
| 57 | 59 | } |
| 58 | 60 | |
| 59 | 61 | $parsed = $this->parser->parse($path); |
| 60 | - if (!$parsed instanceof \Spiral\Views\Loader\ViewPath) { |
|
| 62 | + if (!$parsed instanceof \Spiral\Views\Loader\ViewPath) |
|
| 63 | + { |
|
| 61 | 64 | return false; |
| 62 | 65 | } |
| 63 | 66 | |
| 64 | - if (!isset($this->namespaces[$parsed->getNamespace()])) { |
|
| 67 | + if (!isset($this->namespaces[$parsed->getNamespace()])) |
|
| 68 | + { |
|
| 65 | 69 | return false; |
| 66 | 70 | } |
| 67 | 71 | |
| 68 | - foreach ((array)$this->namespaces[$parsed->getNamespace()] as $directory) { |
|
| 72 | + foreach ((array)$this->namespaces[$parsed->getNamespace()] as $directory) |
|
| 73 | + { |
|
| 69 | 74 | $directory = $this->files->normalizePath($directory, true); |
| 70 | - if ($this->files->exists(\sprintf('%s%s', $directory, $parsed->getBasename()))) { |
|
| 75 | + if ($this->files->exists(\sprintf('%s%s', $directory, $parsed->getBasename()))) |
|
| 76 | + { |
|
| 71 | 77 | $filename = \sprintf('%s%s', $directory, $parsed->getBasename()); |
| 72 | 78 | |
| 73 | 79 | return true; |
@@ -79,7 +85,8 @@ discard block |
||
| 79 | 85 | |
| 80 | 86 | public function load(string $path): ViewSource |
| 81 | 87 | { |
| 82 | - if (!$this->exists($path, $filename, $parsed)) { |
|
| 88 | + if (!$this->exists($path, $filename, $parsed)) |
|
| 89 | + { |
|
| 83 | 90 | $this->dispatcher?->dispatch(new ViewNotFound($path)); |
| 84 | 91 | |
| 85 | 92 | throw new LoaderException(\sprintf('Unable to load view `%s`, file does not exist.', $path)); |
@@ -94,21 +101,27 @@ discard block |
||
| 94 | 101 | |
| 95 | 102 | public function list(?string $namespace = null): array |
| 96 | 103 | { |
| 97 | - if (!$this->parser instanceof \Spiral\Views\Loader\PathParser) { |
|
| 104 | + if (!$this->parser instanceof \Spiral\Views\Loader\PathParser) |
|
| 105 | + { |
|
| 98 | 106 | throw new LoaderException('Unable to list view sources, no extension has been associated.'); |
| 99 | 107 | } |
| 100 | 108 | |
| 101 | 109 | $result = []; |
| 102 | - foreach ($this->namespaces as $ns => $directories) { |
|
| 103 | - if (!empty($namespace) && $namespace != $ns) { |
|
| 110 | + foreach ($this->namespaces as $ns => $directories) |
|
| 111 | + { |
|
| 112 | + if (!empty($namespace) && $namespace != $ns) |
|
| 113 | + { |
|
| 104 | 114 | continue; |
| 105 | 115 | } |
| 106 | 116 | |
| 107 | - foreach ((array)$directories as $directory) { |
|
| 117 | + foreach ((array)$directories as $directory) |
|
| 118 | + { |
|
| 108 | 119 | $files = $this->files->getFiles($directory); |
| 109 | 120 | |
| 110 | - foreach ($files as $filename) { |
|
| 111 | - if (!$this->parser->match($filename)) { |
|
| 121 | + foreach ($files as $filename) |
|
| 122 | + { |
|
| 123 | + if (!$this->parser->match($filename)) |
|
| 124 | + { |
|
| 112 | 125 | // does not belong to this loader |
| 113 | 126 | continue; |
| 114 | 127 | } |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | |
| 29 | 29 | public function getLoader(): LoaderInterface |
| 30 | 30 | { |
| 31 | - if (!$this->loader instanceof \Spiral\Views\LoaderInterface) { |
|
| 31 | + if (!$this->loader instanceof \Spiral\Views\LoaderInterface){ |
|
| 32 | 32 | throw new EngineException('No associated loader found'); |
| 33 | 33 | } |
| 34 | 34 | |
@@ -28,7 +28,8 @@ |
||
| 28 | 28 | |
| 29 | 29 | public function getLoader(): LoaderInterface |
| 30 | 30 | { |
| 31 | - if (!$this->loader instanceof \Spiral\Views\LoaderInterface) { |
|
| 31 | + if (!$this->loader instanceof \Spiral\Views\LoaderInterface) |
|
| 32 | + { |
|
| 32 | 33 | throw new EngineException('No associated loader found'); |
| 33 | 34 | } |
| 34 | 35 | |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | public function reset(?ContextInterface $context = null): void |
| 14 | 14 | { |
| 15 | - if (!$context instanceof \Spiral\Views\ContextInterface) { |
|
| 15 | + if (!$context instanceof \Spiral\Views\ContextInterface){ |
|
| 16 | 16 | $this->cache = []; |
| 17 | 17 | return; |
| 18 | 18 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | public function resetPath(string $path): void |
| 27 | 27 | { |
| 28 | - foreach ($this->cache as &$cache) { |
|
| 28 | + foreach ($this->cache as &$cache){ |
|
| 29 | 29 | unset($cache[$path], $cache); |
| 30 | 30 | } |
| 31 | 31 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function get(ContextInterface $context, string $path): ViewInterface |
| 47 | 47 | { |
| 48 | - if (!$this->has($context, $path)) { |
|
| 48 | + if (!$this->has($context, $path)){ |
|
| 49 | 49 | throw new CacheException(\sprintf('No cache is available for %s.', $path)); |
| 50 | 50 | } |
| 51 | 51 | |
@@ -12,7 +12,8 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | public function reset(?ContextInterface $context = null): void |
| 14 | 14 | { |
| 15 | - if (!$context instanceof \Spiral\Views\ContextInterface) { |
|
| 15 | + if (!$context instanceof \Spiral\Views\ContextInterface) |
|
| 16 | + { |
|
| 16 | 17 | $this->cache = []; |
| 17 | 18 | return; |
| 18 | 19 | } |
@@ -25,7 +26,8 @@ discard block |
||
| 25 | 26 | */ |
| 26 | 27 | public function resetPath(string $path): void |
| 27 | 28 | { |
| 28 | - foreach ($this->cache as &$cache) { |
|
| 29 | + foreach ($this->cache as &$cache) |
|
| 30 | + { |
|
| 29 | 31 | unset($cache[$path], $cache); |
| 30 | 32 | } |
| 31 | 33 | } |
@@ -45,7 +47,8 @@ discard block |
||
| 45 | 47 | */ |
| 46 | 48 | public function get(ContextInterface $context, string $path): ViewInterface |
| 47 | 49 | { |
| 48 | - if (!$this->has($context, $path)) { |
|
| 50 | + if (!$this->has($context, $path)) |
|
| 51 | + { |
|
| 49 | 52 | throw new CacheException(\sprintf('No cache is available for %s.', $path)); |
| 50 | 53 | } |
| 51 | 54 | |
@@ -22,21 +22,21 @@ |
||
| 22 | 22 | public function __construct( |
| 23 | 23 | private readonly SessionConfig $config, |
| 24 | 24 | private readonly FactoryInterface $factory |
| 25 | - ) { |
|
| 25 | + ){ |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | public function initSession(string $clientSignature, ?string $id = null): SessionInterface |
| 29 | 29 | { |
| 30 | - if (\session_status() === PHP_SESSION_ACTIVE) { |
|
| 30 | + if (\session_status() === PHP_SESSION_ACTIVE){ |
|
| 31 | 31 | throw new MultipleSessionException('Unable to initiate session, session already started'); |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | // Initiating proper session handler |
| 35 | - if ($this->config->getHandler() instanceof \Spiral\Core\Container\Autowire) { |
|
| 36 | - try { |
|
| 35 | + if ($this->config->getHandler() instanceof \Spiral\Core\Container\Autowire){ |
|
| 36 | + try{ |
|
| 37 | 37 | $handler = $this->config->getHandler()->resolve($this->factory); |
| 38 | - } catch (\Throwable | ContainerExceptionInterface $e) { |
|
| 39 | - throw new SessionException($e->getMessage(), (int) $e->getCode(), $e); |
|
| 38 | + }catch (\Throwable | ContainerExceptionInterface $e){ |
|
| 39 | + throw new SessionException($e->getMessage(), (int)$e->getCode(), $e); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | \session_set_save_handler($handler, true); |
@@ -27,15 +27,20 @@ |
||
| 27 | 27 | |
| 28 | 28 | public function initSession(string $clientSignature, ?string $id = null): SessionInterface |
| 29 | 29 | { |
| 30 | - if (\session_status() === PHP_SESSION_ACTIVE) { |
|
| 30 | + if (\session_status() === PHP_SESSION_ACTIVE) |
|
| 31 | + { |
|
| 31 | 32 | throw new MultipleSessionException('Unable to initiate session, session already started'); |
| 32 | 33 | } |
| 33 | 34 | |
| 34 | 35 | // Initiating proper session handler |
| 35 | - if ($this->config->getHandler() instanceof \Spiral\Core\Container\Autowire) { |
|
| 36 | - try { |
|
| 36 | + if ($this->config->getHandler() instanceof \Spiral\Core\Container\Autowire) |
|
| 37 | + { |
|
| 38 | + try |
|
| 39 | + { |
|
| 37 | 40 | $handler = $this->config->getHandler()->resolve($this->factory); |
| 38 | - } catch (\Throwable | ContainerExceptionInterface $e) { |
|
| 41 | + } |
|
| 42 | + catch (\Throwable | ContainerExceptionInterface $e) |
|
| 43 | + { |
|
| 39 | 44 | throw new SessionException($e->getMessage(), (int) $e->getCode(), $e); |
| 40 | 45 | } |
| 41 | 46 | |