@@ -14,11 +14,11 @@ discard block |
||
| 14 | 14 | /** |
| 15 | 15 | * @throws SerializeException |
| 16 | 16 | */ |
| 17 | - public function serialize(mixed $payload): string|\Stringable |
|
| 17 | + public function serialize(mixed $payload): string | \Stringable |
|
| 18 | 18 | { |
| 19 | - try { |
|
| 19 | + try{ |
|
| 20 | 20 | return \json_encode($payload, JSON_THROW_ON_ERROR); |
| 21 | - } catch (\JsonException $e) { |
|
| 21 | + }catch (\JsonException $e){ |
|
| 22 | 22 | throw new SerializeException($e->getMessage(), $e->getCode(), $e); |
| 23 | 23 | } |
| 24 | 24 | } |
@@ -26,17 +26,17 @@ discard block |
||
| 26 | 26 | /** |
| 27 | 27 | * @throws \JsonException |
| 28 | 28 | */ |
| 29 | - public function unserialize(\Stringable|string $payload, object|string|null $type = null): mixed |
|
| 29 | + public function unserialize(\Stringable | string $payload, object | string | null $type = null): mixed |
|
| 30 | 30 | { |
| 31 | - if ($type !== null) { |
|
| 31 | + if ($type !== null){ |
|
| 32 | 32 | throw new InvalidArgumentException( |
| 33 | 33 | \sprintf('Serializer `%s` does not support data hydration to an object.', self::class) |
| 34 | 34 | ); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - try { |
|
| 38 | - return \json_decode((string) $payload, true, 512, JSON_THROW_ON_ERROR); |
|
| 39 | - } catch (\JsonException $e) { |
|
| 37 | + try{ |
|
| 38 | + return \json_decode((string)$payload, true, 512, JSON_THROW_ON_ERROR); |
|
| 39 | + }catch (\JsonException $e){ |
|
| 40 | 40 | throw new UnserializeException($e->getMessage(), $e->getCode(), $e); |
| 41 | 41 | } |
| 42 | 42 | } |
@@ -16,9 +16,12 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | public function serialize(mixed $payload): string|\Stringable |
| 18 | 18 | { |
| 19 | - try { |
|
| 19 | + try |
|
| 20 | + { |
|
| 20 | 21 | return \json_encode($payload, JSON_THROW_ON_ERROR); |
| 21 | - } catch (\JsonException $e) { |
|
| 22 | + } |
|
| 23 | + catch (\JsonException $e) |
|
| 24 | + { |
|
| 22 | 25 | throw new SerializeException($e->getMessage(), $e->getCode(), $e); |
| 23 | 26 | } |
| 24 | 27 | } |
@@ -28,15 +31,19 @@ discard block |
||
| 28 | 31 | */ |
| 29 | 32 | public function unserialize(\Stringable|string $payload, object|string|null $type = null): mixed |
| 30 | 33 | { |
| 31 | - if ($type !== null) { |
|
| 34 | + if ($type !== null) |
|
| 35 | + { |
|
| 32 | 36 | throw new InvalidArgumentException( |
| 33 | 37 | \sprintf('Serializer `%s` does not support data hydration to an object.', self::class) |
| 34 | 38 | ); |
| 35 | 39 | } |
| 36 | 40 | |
| 37 | - try { |
|
| 41 | + try |
|
| 42 | + { |
|
| 38 | 43 | return \json_decode((string) $payload, true, 512, JSON_THROW_ON_ERROR); |
| 39 | - } catch (\JsonException $e) { |
|
| 44 | + } |
|
| 45 | + catch (\JsonException $e) |
|
| 46 | + { |
|
| 40 | 47 | throw new UnserializeException($e->getMessage(), $e->getCode(), $e); |
| 41 | 48 | } |
| 42 | 49 | } |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | |
| 7 | 7 | interface SerializerInterface |
| 8 | 8 | { |
| 9 | - public function serialize(mixed $payload): string|\Stringable; |
|
| 9 | + public function serialize(mixed $payload): string | \Stringable; |
|
| 10 | 10 | |
| 11 | - public function unserialize(string|\Stringable $payload, string|object|null $type = null): mixed; |
|
| 11 | + public function unserialize(string | \Stringable $payload, string | object | null $type = null): mixed; |
|
| 12 | 12 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | public function __construct( |
| 10 | 10 | protected readonly SerializerRegistry $serializers, |
| 11 | 11 | protected readonly string $defaultFormat |
| 12 | - ) { |
|
| 12 | + ){ |
|
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | public function getSerializer(string $format = null): SerializerInterface |
@@ -17,14 +17,14 @@ discard block |
||
| 17 | 17 | return $this->serializers->get($format ?? $this->defaultFormat); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - public function serialize(mixed $payload, ?string $format = null): string|\Stringable |
|
| 20 | + public function serialize(mixed $payload, ?string $format = null): string | \Stringable |
|
| 21 | 21 | { |
| 22 | 22 | return $this->getSerializer($format ?? $this->defaultFormat)->serialize($payload); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public function unserialize( |
| 26 | - string|\Stringable $payload, |
|
| 27 | - string|object|null $type = null, |
|
| 26 | + string | \Stringable $payload, |
|
| 27 | + string | object | null $type = null, |
|
| 28 | 28 | ?string $format = null |
| 29 | 29 | ): mixed { |
| 30 | 30 | return $this->getSerializer($format ?? $this->defaultFormat)->unserialize($payload, $type); |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | |
| 14 | 14 | public function __construct(array $serializers = []) |
| 15 | 15 | { |
| 16 | - foreach ($serializers as $name => $serializer) { |
|
| 16 | + foreach ($serializers as $name => $serializer){ |
|
| 17 | 17 | $this->register($name, $serializer); |
| 18 | 18 | } |
| 19 | 19 | } |
@@ -13,7 +13,8 @@ |
||
| 13 | 13 | |
| 14 | 14 | public function __construct(array $serializers = []) |
| 15 | 15 | { |
| 16 | - foreach ($serializers as $name => $serializer) { |
|
| 16 | + foreach ($serializers as $name => $serializer) |
|
| 17 | + { |
|
| 17 | 18 | $this->register($name, $serializer); |
| 18 | 19 | } |
| 19 | 20 | } |
@@ -1,3 +1,3 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -return ; |
|
| 3 | +return; |
|
@@ -17,15 +17,15 @@ discard block |
||
| 17 | 17 | public function __construct( |
| 18 | 18 | string $directory, |
| 19 | 19 | private readonly array $loaders = [] |
| 20 | - ) { |
|
| 20 | + ){ |
|
| 21 | 21 | $this->directory = \rtrim($directory, '/'); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public function has(string $section): bool |
| 25 | 25 | { |
| 26 | - foreach ($this->loaderExtensions() as $extension) { |
|
| 26 | + foreach ($this->loaderExtensions() as $extension){ |
|
| 27 | 27 | $filename = \sprintf('%s/%s.%s', $this->directory, $section, $extension); |
| 28 | - if (\file_exists($filename)) { |
|
| 28 | + if (\file_exists($filename)){ |
|
| 29 | 29 | return true; |
| 30 | 30 | } |
| 31 | 31 | } |
@@ -35,15 +35,15 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | public function load(string $section): array |
| 37 | 37 | { |
| 38 | - foreach ($this->loaderExtensions() as $extension) { |
|
| 38 | + foreach ($this->loaderExtensions() as $extension){ |
|
| 39 | 39 | $filename = \sprintf('%s/%s.%s', $this->directory, $section, $extension); |
| 40 | - if (!\file_exists($filename)) { |
|
| 40 | + if (!\file_exists($filename)){ |
|
| 41 | 41 | continue; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - try { |
|
| 44 | + try{ |
|
| 45 | 45 | return $this->getLoader($extension)->loadFile($section, $filename); |
| 46 | - } catch (LoaderException $e) { |
|
| 46 | + }catch (LoaderException $e){ |
|
| 47 | 47 | throw new LoaderException("Unable to load config `{$section}`: {$e->getMessage()}", $e->getCode(), $e); |
| 48 | 48 | } |
| 49 | 49 | } |
@@ -23,9 +23,11 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | public function has(string $section): bool |
| 25 | 25 | { |
| 26 | - foreach ($this->loaderExtensions() as $extension) { |
|
| 26 | + foreach ($this->loaderExtensions() as $extension) |
|
| 27 | + { |
|
| 27 | 28 | $filename = \sprintf('%s/%s.%s', $this->directory, $section, $extension); |
| 28 | - if (\file_exists($filename)) { |
|
| 29 | + if (\file_exists($filename)) |
|
| 30 | + { |
|
| 29 | 31 | return true; |
| 30 | 32 | } |
| 31 | 33 | } |
@@ -35,15 +37,20 @@ discard block |
||
| 35 | 37 | |
| 36 | 38 | public function load(string $section): array |
| 37 | 39 | { |
| 38 | - foreach ($this->loaderExtensions() as $extension) { |
|
| 40 | + foreach ($this->loaderExtensions() as $extension) |
|
| 41 | + { |
|
| 39 | 42 | $filename = \sprintf('%s/%s.%s', $this->directory, $section, $extension); |
| 40 | - if (!\file_exists($filename)) { |
|
| 43 | + if (!\file_exists($filename)) |
|
| 44 | + { |
|
| 41 | 45 | continue; |
| 42 | 46 | } |
| 43 | 47 | |
| 44 | - try { |
|
| 48 | + try |
|
| 49 | + { |
|
| 45 | 50 | return $this->getLoader($extension)->loadFile($section, $filename); |
| 46 | - } catch (LoaderException $e) { |
|
| 51 | + } |
|
| 52 | + catch (LoaderException $e) |
|
| 53 | + { |
|
| 47 | 54 | throw new LoaderException("Unable to load config `{$section}`: {$e->getMessage()}", $e->getCode(), $e); |
| 48 | 55 | } |
| 49 | 56 | } |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | $content = \file_get_contents($filename); |
| 14 | 14 | $data = \json_decode($content, true); |
| 15 | 15 | |
| 16 | - if (\is_null($data)) { |
|
| 16 | + if (\is_null($data)){ |
|
| 17 | 17 | throw new LoaderException(\json_last_error_msg(), \json_last_error()); |
| 18 | 18 | } |
| 19 | 19 | |
@@ -13,7 +13,8 @@ |
||
| 13 | 13 | $content = \file_get_contents($filename); |
| 14 | 14 | $data = \json_decode($content, true); |
| 15 | 15 | |
| 16 | - if (\is_null($data)) { |
|
| 16 | + if (\is_null($data)) |
|
| 17 | + { |
|
| 17 | 18 | throw new LoaderException(\json_last_error_msg(), \json_last_error()); |
| 18 | 19 | } |
| 19 | 20 | |
@@ -15,15 +15,15 @@ |
||
| 15 | 15 | { |
| 16 | 16 | public function __construct( |
| 17 | 17 | private readonly ContainerInterface $container |
| 18 | - ) { |
|
| 18 | + ){ |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public function loadFile(string $section, string $filename): array |
| 22 | 22 | { |
| 23 | - try { |
|
| 23 | + try{ |
|
| 24 | 24 | return ContainerScope::runScope($this->container, static fn () => require $filename); |
| 25 | - } catch (\Throwable $e) { |
|
| 26 | - throw new LoaderException($e->getMessage(), (int) $e->getCode(), $e); |
|
| 25 | + }catch (\Throwable $e){ |
|
| 26 | + throw new LoaderException($e->getMessage(), (int)$e->getCode(), $e); |
|
| 27 | 27 | } |
| 28 | 28 | } |
| 29 | 29 | } |
@@ -20,9 +20,12 @@ |
||
| 20 | 20 | |
| 21 | 21 | public function loadFile(string $section, string $filename): array |
| 22 | 22 | { |
| 23 | - try { |
|
| 23 | + try |
|
| 24 | + { |
|
| 24 | 25 | return ContainerScope::runScope($this->container, static fn () => require $filename); |
| 25 | - } catch (\Throwable $e) { |
|
| 26 | + } |
|
| 27 | + catch (\Throwable $e) |
|
| 28 | + { |
|
| 26 | 29 | throw new LoaderException($e->getMessage(), (int) $e->getCode(), $e); |
| 27 | 30 | } |
| 28 | 31 | } |
@@ -18,26 +18,26 @@ |
||
| 18 | 18 | string $position, |
| 19 | 19 | private readonly ?string $key, |
| 20 | 20 | private mixed $value = null |
| 21 | - ) { |
|
| 21 | + ){ |
|
| 22 | 22 | $this->position = $position === '.' ? '' : $position; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public function patch(array $config): array |
| 26 | 26 | { |
| 27 | - try { |
|
| 27 | + try{ |
|
| 28 | 28 | $target = &$this->dotGet($config, $this->position); |
| 29 | 29 | |
| 30 | - if ($this->key !== null) { |
|
| 30 | + if ($this->key !== null){ |
|
| 31 | 31 | unset($target[$this->key]); |
| 32 | - } else { |
|
| 33 | - foreach ($target as $key => $value) { |
|
| 34 | - if ($value === $this->value) { |
|
| 32 | + }else{ |
|
| 33 | + foreach ($target as $key => $value){ |
|
| 34 | + if ($value === $this->value){ |
|
| 35 | 35 | unset($target[$key]); |
| 36 | 36 | break; |
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | } |
| 40 | - } catch (DotNotFoundException) { |
|
| 40 | + }catch (DotNotFoundException){ |
|
| 41 | 41 | // doing nothing when section not found |
| 42 | 42 | } |
| 43 | 43 | |
@@ -24,20 +24,28 @@ |
||
| 24 | 24 | |
| 25 | 25 | public function patch(array $config): array |
| 26 | 26 | { |
| 27 | - try { |
|
| 27 | + try |
|
| 28 | + { |
|
| 28 | 29 | $target = &$this->dotGet($config, $this->position); |
| 29 | 30 | |
| 30 | - if ($this->key !== null) { |
|
| 31 | + if ($this->key !== null) |
|
| 32 | + { |
|
| 31 | 33 | unset($target[$this->key]); |
| 32 | - } else { |
|
| 33 | - foreach ($target as $key => $value) { |
|
| 34 | - if ($value === $this->value) { |
|
| 34 | + } |
|
| 35 | + else |
|
| 36 | + { |
|
| 37 | + foreach ($target as $key => $value) |
|
| 38 | + { |
|
| 39 | + if ($value === $this->value) |
|
| 40 | + { |
|
| 35 | 41 | unset($target[$key]); |
| 36 | 42 | break; |
| 37 | 43 | } |
| 38 | 44 | } |
| 39 | 45 | } |
| 40 | - } catch (DotNotFoundException) { |
|
| 46 | + } |
|
| 47 | + catch (DotNotFoundException) |
|
| 48 | + { |
|
| 41 | 49 | // doing nothing when section not found |
| 42 | 50 | } |
| 43 | 51 | |