@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | public function addListener(callable $listener): self |
| 16 | 16 | { |
| 17 | - if (!\in_array($listener, $this->listeners, true)) { |
|
| 17 | + if (!\in_array($listener, $this->listeners, true)){ |
|
| 18 | 18 | $this->listeners[] = $listener; |
| 19 | 19 | } |
| 20 | 20 | |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | public function removeListener(callable $listener): void |
| 25 | 25 | { |
| 26 | 26 | $key = \array_search($listener, $this->listeners, true); |
| 27 | - if ($key !== null) { |
|
| 27 | + if ($key !== null){ |
|
| 28 | 28 | unset($this->listeners[$key]); |
| 29 | 29 | } |
| 30 | 30 | } |
@@ -14,7 +14,8 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | public function addListener(callable $listener): self |
| 16 | 16 | { |
| 17 | - if (!\in_array($listener, $this->listeners, true)) { |
|
| 17 | + if (!\in_array($listener, $this->listeners, true)) |
|
| 18 | + { |
|
| 18 | 19 | $this->listeners[] = $listener; |
| 19 | 20 | } |
| 20 | 21 | |
@@ -24,7 +25,8 @@ discard block |
||
| 24 | 25 | public function removeListener(callable $listener): void |
| 25 | 26 | { |
| 26 | 27 | $key = \array_search($listener, $this->listeners, true); |
| 27 | - if ($key !== null) { |
|
| 28 | + if ($key !== null) |
|
| 29 | + { |
|
| 28 | 30 | unset($this->listeners[$key]); |
| 29 | 31 | } |
| 30 | 32 | } |
@@ -19,7 +19,7 @@ |
||
| 19 | 19 | public function __construct( |
| 20 | 20 | callable $receptor, |
| 21 | 21 | private string $channel |
| 22 | - ) { |
|
| 22 | + ){ |
|
| 23 | 23 | $this->receptor = $receptor(...); |
| 24 | 24 | } |
| 25 | 25 | |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | { |
| 15 | 15 | public function __construct( |
| 16 | 16 | private readonly ListenerRegistryInterface $listenedRegistry |
| 17 | - ) { |
|
| 17 | + ){ |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | public function getLogger(string $channel): LoggerInterface |
@@ -27,12 +27,12 @@ discard block |
||
| 27 | 27 | $e = new LogEvent( |
| 28 | 28 | new \DateTime(), |
| 29 | 29 | $channel, |
| 30 | - (string) $level, |
|
| 30 | + (string)$level, |
|
| 31 | 31 | $message, |
| 32 | 32 | $context |
| 33 | 33 | ); |
| 34 | 34 | |
| 35 | - foreach ($this->listenedRegistry->getListeners() as $listener) { |
|
| 35 | + foreach ($this->listenedRegistry->getListeners() as $listener){ |
|
| 36 | 36 | \call_user_func($listener, $e); |
| 37 | 37 | } |
| 38 | 38 | } |
@@ -32,7 +32,8 @@ |
||
| 32 | 32 | $context |
| 33 | 33 | ); |
| 34 | 34 | |
| 35 | - foreach ($this->listenedRegistry->getListeners() as $listener) { |
|
| 35 | + foreach ($this->listenedRegistry->getListeners() as $listener) |
|
| 36 | + { |
|
| 36 | 37 | \call_user_func($listener, $e); |
| 37 | 38 | } |
| 38 | 39 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | public function getDefaultStorage(): string |
| 33 | 33 | { |
| 34 | - if (!\is_string($this->config['default'])) { |
|
| 34 | + if (!\is_string($this->config['default'])){ |
|
| 35 | 35 | throw new InvalidArgumentException('Default cache storage config value must be a string'); |
| 36 | 36 | } |
| 37 | 37 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | public function getStorageConfig(string $name): array |
| 42 | 42 | { |
| 43 | - if (!isset($this->config['storages'][$name])) { |
|
| 43 | + if (!isset($this->config['storages'][$name])){ |
|
| 44 | 44 | throw new InvalidArgumentException( |
| 45 | 45 | \sprintf('Config for storage `%s` is not defined.', $name) |
| 46 | 46 | ); |
@@ -48,19 +48,19 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | $config = $this->config['storages'][$name]; |
| 50 | 50 | |
| 51 | - if (!isset($config['type'])) { |
|
| 51 | + if (!isset($config['type'])){ |
|
| 52 | 52 | throw new InvalidArgumentException( |
| 53 | 53 | \sprintf('Storage type for `%s` is not defined.', $name) |
| 54 | 54 | ); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - if (!\is_string($config['type'])) { |
|
| 57 | + if (!\is_string($config['type'])){ |
|
| 58 | 58 | throw new InvalidArgumentException( |
| 59 | 59 | \sprintf('Storage type value for `%s` must be a string', $name) |
| 60 | 60 | ); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - if (isset($this->config['typeAliases'][$config['type']])) { |
|
| 63 | + if (isset($this->config['typeAliases'][$config['type']])){ |
|
| 64 | 64 | $config['type'] = $this->config['typeAliases'][$config['type']]; |
| 65 | 65 | } |
| 66 | 66 | |
@@ -31,7 +31,8 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | public function getDefaultStorage(): string |
| 33 | 33 | { |
| 34 | - if (!\is_string($this->config['default'])) { |
|
| 34 | + if (!\is_string($this->config['default'])) |
|
| 35 | + { |
|
| 35 | 36 | throw new InvalidArgumentException('Default cache storage config value must be a string'); |
| 36 | 37 | } |
| 37 | 38 | |
@@ -40,7 +41,8 @@ discard block |
||
| 40 | 41 | |
| 41 | 42 | public function getStorageConfig(string $name): array |
| 42 | 43 | { |
| 43 | - if (!isset($this->config['storages'][$name])) { |
|
| 44 | + if (!isset($this->config['storages'][$name])) |
|
| 45 | + { |
|
| 44 | 46 | throw new InvalidArgumentException( |
| 45 | 47 | \sprintf('Config for storage `%s` is not defined.', $name) |
| 46 | 48 | ); |
@@ -48,19 +50,22 @@ discard block |
||
| 48 | 50 | |
| 49 | 51 | $config = $this->config['storages'][$name]; |
| 50 | 52 | |
| 51 | - if (!isset($config['type'])) { |
|
| 53 | + if (!isset($config['type'])) |
|
| 54 | + { |
|
| 52 | 55 | throw new InvalidArgumentException( |
| 53 | 56 | \sprintf('Storage type for `%s` is not defined.', $name) |
| 54 | 57 | ); |
| 55 | 58 | } |
| 56 | 59 | |
| 57 | - if (!\is_string($config['type'])) { |
|
| 60 | + if (!\is_string($config['type'])) |
|
| 61 | + { |
|
| 58 | 62 | throw new InvalidArgumentException( |
| 59 | 63 | \sprintf('Storage type value for `%s` must be a string', $name) |
| 60 | 64 | ); |
| 61 | 65 | } |
| 62 | 66 | |
| 63 | - if (isset($this->config['typeAliases'][$config['type']])) { |
|
| 67 | + if (isset($this->config['typeAliases'][$config['type']])) |
|
| 68 | + { |
|
| 64 | 69 | $config['type'] = $this->config['typeAliases'][$config['type']]; |
| 65 | 70 | } |
| 66 | 71 | |
@@ -9,6 +9,6 @@ |
||
| 9 | 9 | public function __construct( |
| 10 | 10 | public readonly string $key, |
| 11 | 11 | public readonly mixed $value, |
| 12 | - ) { |
|
| 12 | + ){ |
|
| 13 | 13 | } |
| 14 | 14 | } |
@@ -8,6 +8,6 @@ |
||
| 8 | 8 | { |
| 9 | 9 | public function __construct( |
| 10 | 10 | public readonly string $key, |
| 11 | - ) { |
|
| 11 | + ){ |
|
| 12 | 12 | } |
| 13 | 13 | } |
@@ -9,6 +9,6 @@ |
||
| 9 | 9 | public function __construct( |
| 10 | 10 | public readonly string $key, |
| 11 | 11 | public readonly mixed $value |
| 12 | - ) { |
|
| 12 | + ){ |
|
| 13 | 13 | } |
| 14 | 14 | } |
@@ -19,26 +19,26 @@ discard block |
||
| 19 | 19 | { |
| 20 | 20 | public function __construct( |
| 21 | 21 | private readonly CacheStorageProviderInterface $provider |
| 22 | - ) { |
|
| 22 | + ){ |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public function createInjection(ReflectionClass $class, string $context = null): CacheInterface |
| 26 | 26 | { |
| 27 | - try { |
|
| 28 | - if ($context === null) { |
|
| 27 | + try{ |
|
| 28 | + if ($context === null){ |
|
| 29 | 29 | $connection = $this->provider->storage(); |
| 30 | - } else { |
|
| 30 | + }else{ |
|
| 31 | 31 | // Get Cache by context |
| 32 | - try { |
|
| 32 | + try{ |
|
| 33 | 33 | $connection = $this->provider->storage($context); |
| 34 | - } catch (InvalidArgumentException) { |
|
| 34 | + }catch (InvalidArgumentException){ |
|
| 35 | 35 | // Case when context doesn't match to configured connections |
| 36 | 36 | return $this->provider->storage(); |
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | $this->matchType($class, $context, $connection); |
| 41 | - } catch (\Throwable $e) { |
|
| 41 | + }catch (\Throwable $e){ |
|
| 42 | 42 | throw new ContainerException(sprintf("Can't inject the required cache. %s", $e->getMessage()), 0, $e); |
| 43 | 43 | } |
| 44 | 44 | |
@@ -52,11 +52,11 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | private function matchType(ReflectionClass $class, ?string $context, CacheInterface $connection): void |
| 54 | 54 | { |
| 55 | - if ($connection::class === CacheRepository::class) { |
|
| 55 | + if ($connection::class === CacheRepository::class){ |
|
| 56 | 56 | $connection = $connection->getStorage(); |
| 57 | 57 | } |
| 58 | 58 | $className = $class->getName(); |
| 59 | - if ($className !== CacheInterface::class && !$connection instanceof $className) { |
|
| 59 | + if ($className !== CacheInterface::class && !$connection instanceof $className){ |
|
| 60 | 60 | throw new \RuntimeException( |
| 61 | 61 | \sprintf( |
| 62 | 62 | "The cache obtained by the context `%s` doesn't match the type `%s`.", |
@@ -24,21 +24,30 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | public function createInjection(ReflectionClass $class, string $context = null): CacheInterface |
| 26 | 26 | { |
| 27 | - try { |
|
| 28 | - if ($context === null) { |
|
| 27 | + try |
|
| 28 | + { |
|
| 29 | + if ($context === null) |
|
| 30 | + { |
|
| 29 | 31 | $connection = $this->provider->storage(); |
| 30 | - } else { |
|
| 32 | + } |
|
| 33 | + else |
|
| 34 | + { |
|
| 31 | 35 | // Get Cache by context |
| 32 | - try { |
|
| 36 | + try |
|
| 37 | + { |
|
| 33 | 38 | $connection = $this->provider->storage($context); |
| 34 | - } catch (InvalidArgumentException) { |
|
| 39 | + } |
|
| 40 | + catch (InvalidArgumentException) |
|
| 41 | + { |
|
| 35 | 42 | // Case when context doesn't match to configured connections |
| 36 | 43 | return $this->provider->storage(); |
| 37 | 44 | } |
| 38 | 45 | } |
| 39 | 46 | |
| 40 | 47 | $this->matchType($class, $context, $connection); |
| 41 | - } catch (\Throwable $e) { |
|
| 48 | + } |
|
| 49 | + catch (\Throwable $e) |
|
| 50 | + { |
|
| 42 | 51 | throw new ContainerException(sprintf("Can't inject the required cache. %s", $e->getMessage()), 0, $e); |
| 43 | 52 | } |
| 44 | 53 | |
@@ -52,11 +61,13 @@ discard block |
||
| 52 | 61 | */ |
| 53 | 62 | private function matchType(ReflectionClass $class, ?string $context, CacheInterface $connection): void |
| 54 | 63 | { |
| 55 | - if ($connection::class === CacheRepository::class) { |
|
| 64 | + if ($connection::class === CacheRepository::class) |
|
| 65 | + { |
|
| 56 | 66 | $connection = $connection->getStorage(); |
| 57 | 67 | } |
| 58 | 68 | $className = $class->getName(); |
| 59 | - if ($className !== CacheInterface::class && !$connection instanceof $className) { |
|
| 69 | + if ($className !== CacheInterface::class && !$connection instanceof $className) |
|
| 70 | + { |
|
| 60 | 71 | throw new \RuntimeException( |
| 61 | 72 | \sprintf( |
| 62 | 73 | "The cache obtained by the context `%s` doesn't match the type `%s`.", |
@@ -19,14 +19,14 @@ discard block |
||
| 19 | 19 | public function __construct( |
| 20 | 20 | protected CacheInterface $storage, |
| 21 | 21 | protected ?EventDispatcherInterface $dispatcher = null |
| 22 | - ) { |
|
| 22 | + ){ |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public function get(string $key, mixed $default = null): mixed |
| 26 | 26 | { |
| 27 | 27 | $value = $this->storage->get($key); |
| 28 | 28 | |
| 29 | - if ($value === null) { |
|
| 29 | + if ($value === null){ |
|
| 30 | 30 | $this->dispatcher?->dispatch(new CacheMissed($key)); |
| 31 | 31 | |
| 32 | 32 | return $default; |
@@ -37,11 +37,11 @@ discard block |
||
| 37 | 37 | return $value; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - public function set(string $key, mixed $value, \DateInterval|int|null $ttl = null): bool |
|
| 40 | + public function set(string $key, mixed $value, \DateInterval | int | null $ttl = null): bool |
|
| 41 | 41 | { |
| 42 | 42 | $result = $this->storage->set($key, $value, $ttl); |
| 43 | 43 | |
| 44 | - if ($result) { |
|
| 44 | + if ($result){ |
|
| 45 | 45 | $this->dispatcher?->dispatch(new KeyWritten($key, $value)); |
| 46 | 46 | } |
| 47 | 47 | |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | { |
| 53 | 53 | $result = $this->storage->delete($key); |
| 54 | 54 | |
| 55 | - if ($result) { |
|
| 55 | + if ($result){ |
|
| 56 | 56 | $this->dispatcher?->dispatch(new KeyDeleted($key)); |
| 57 | 57 | } |
| 58 | 58 | |
@@ -68,18 +68,18 @@ discard block |
||
| 68 | 68 | { |
| 69 | 69 | $result = []; |
| 70 | 70 | |
| 71 | - foreach ($keys as $key) { |
|
| 71 | + foreach ($keys as $key){ |
|
| 72 | 72 | $result[$key] = $this->get($key, $default); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | return $result; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - public function setMultiple(iterable $values, \DateInterval|int|null $ttl = null): bool |
|
| 78 | + public function setMultiple(iterable $values, \DateInterval | int | null $ttl = null): bool |
|
| 79 | 79 | { |
| 80 | 80 | $state = null; |
| 81 | 81 | |
| 82 | - foreach ($values as $key => $value) { |
|
| 82 | + foreach ($values as $key => $value){ |
|
| 83 | 83 | $result = $this->set($key, $value, $ttl); |
| 84 | 84 | $state = \is_null($state) ? $result : $result && $state; |
| 85 | 85 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | public function deleteMultiple(iterable $keys): bool |
| 91 | 91 | { |
| 92 | 92 | $state = null; |
| 93 | - foreach ($keys as $key) { |
|
| 93 | + foreach ($keys as $key){ |
|
| 94 | 94 | $result = $this->delete($key); |
| 95 | 95 | $state = \is_null($state) ? $result : $result && $state; |
| 96 | 96 | } |
@@ -26,7 +26,8 @@ discard block |
||
| 26 | 26 | { |
| 27 | 27 | $value = $this->storage->get($key); |
| 28 | 28 | |
| 29 | - if ($value === null) { |
|
| 29 | + if ($value === null) |
|
| 30 | + { |
|
| 30 | 31 | $this->dispatcher?->dispatch(new CacheMissed($key)); |
| 31 | 32 | |
| 32 | 33 | return $default; |
@@ -41,7 +42,8 @@ discard block |
||
| 41 | 42 | { |
| 42 | 43 | $result = $this->storage->set($key, $value, $ttl); |
| 43 | 44 | |
| 44 | - if ($result) { |
|
| 45 | + if ($result) |
|
| 46 | + { |
|
| 45 | 47 | $this->dispatcher?->dispatch(new KeyWritten($key, $value)); |
| 46 | 48 | } |
| 47 | 49 | |
@@ -52,7 +54,8 @@ discard block |
||
| 52 | 54 | { |
| 53 | 55 | $result = $this->storage->delete($key); |
| 54 | 56 | |
| 55 | - if ($result) { |
|
| 57 | + if ($result) |
|
| 58 | + { |
|
| 56 | 59 | $this->dispatcher?->dispatch(new KeyDeleted($key)); |
| 57 | 60 | } |
| 58 | 61 | |
@@ -68,7 +71,8 @@ discard block |
||
| 68 | 71 | { |
| 69 | 72 | $result = []; |
| 70 | 73 | |
| 71 | - foreach ($keys as $key) { |
|
| 74 | + foreach ($keys as $key) |
|
| 75 | + { |
|
| 72 | 76 | $result[$key] = $this->get($key, $default); |
| 73 | 77 | } |
| 74 | 78 | |
@@ -79,7 +83,8 @@ discard block |
||
| 79 | 83 | { |
| 80 | 84 | $state = null; |
| 81 | 85 | |
| 82 | - foreach ($values as $key => $value) { |
|
| 86 | + foreach ($values as $key => $value) |
|
| 87 | + { |
|
| 83 | 88 | $result = $this->set($key, $value, $ttl); |
| 84 | 89 | $state = \is_null($state) ? $result : $result && $state; |
| 85 | 90 | } |
@@ -90,7 +95,8 @@ discard block |
||
| 90 | 95 | public function deleteMultiple(iterable $keys): bool |
| 91 | 96 | { |
| 92 | 97 | $state = null; |
| 93 | - foreach ($keys as $key) { |
|
| 98 | + foreach ($keys as $key) |
|
| 99 | + { |
|
| 94 | 100 | $result = $this->delete($key); |
| 95 | 101 | $state = \is_null($state) ? $result : $result && $state; |
| 96 | 102 | } |