@@ -50,7 +50,7 @@ |
||
| 50 | 50 | $dispatcher |
| 51 | 51 | ->expects(self::exactly(2)) |
| 52 | 52 | ->method('dispatch') |
| 53 | - ->with($this->callback(static fn (Routing|RouteMatched $event): bool => $event->request instanceof ServerRequest)); |
|
| 53 | + ->with($this->callback(static fn (Routing | RouteMatched $event): bool => $event->request instanceof ServerRequest)); |
|
| 54 | 54 | |
| 55 | 55 | $router = $this->makeRouter('', $dispatcher); |
| 56 | 56 | $router->setDefault($route); |
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | $response = new Response($code); |
| 34 | 34 | $response = $response->withStatus($code, $reasonPhrase); |
| 35 | 35 | |
| 36 | - foreach ($this->config->getBaseHeaders() as $header => $value) { |
|
| 36 | + foreach ($this->config->getBaseHeaders() as $header => $value){ |
|
| 37 | 37 | $response = $response->withAddedHeader($header, $value); |
| 38 | 38 | } |
| 39 | 39 | |
@@ -33,7 +33,8 @@ |
||
| 33 | 33 | $response = new Response($code); |
| 34 | 34 | $response = $response->withStatus($code, $reasonPhrase); |
| 35 | 35 | |
| 36 | - foreach ($this->config->getBaseHeaders() as $header => $value) { |
|
| 36 | + foreach ($this->config->getBaseHeaders() as $header => $value) |
|
| 37 | + { |
|
| 37 | 38 | $response = $response->withAddedHeader($header, $value); |
| 38 | 39 | } |
| 39 | 40 | |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | public function __construct( |
| 14 | 14 | private readonly RouteCollection $parent, |
| 15 | 15 | private readonly RouteCollection $routes |
| 16 | - ) { |
|
| 16 | + ){ |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | public function __destruct() |
@@ -23,17 +23,17 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | public function __sleep(): array |
| 25 | 25 | { |
| 26 | - throw new \BadMethodCallException('Cannot unserialize ' . self::class); |
|
| 26 | + throw new \BadMethodCallException('Cannot unserialize '.self::class); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | public function __wakeup() |
| 30 | 30 | { |
| 31 | - throw new \BadMethodCallException('Cannot unserialize ' . self::class); |
|
| 31 | + throw new \BadMethodCallException('Cannot unserialize '.self::class); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | public function defaults(array $defaults): self |
| 35 | 35 | { |
| 36 | - foreach ($this->routes->all() as $configurator) { |
|
| 36 | + foreach ($this->routes->all() as $configurator){ |
|
| 37 | 37 | $configurator->defaults($defaults); |
| 38 | 38 | } |
| 39 | 39 | |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | public function group(string $group): self |
| 44 | 44 | { |
| 45 | - foreach ($this->routes->all() as $configurator) { |
|
| 45 | + foreach ($this->routes->all() as $configurator){ |
|
| 46 | 46 | $configurator->group($group); |
| 47 | 47 | } |
| 48 | 48 | |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | public function prefix(string $prefix): self |
| 53 | 53 | { |
| 54 | - foreach ($this->routes->all() as $configurator) { |
|
| 54 | + foreach ($this->routes->all() as $configurator){ |
|
| 55 | 55 | $configurator->prefix($prefix); |
| 56 | 56 | } |
| 57 | 57 | |
@@ -60,16 +60,16 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | public function core(CoreInterface $core): self |
| 62 | 62 | { |
| 63 | - foreach ($this->routes->all() as $configurator) { |
|
| 63 | + foreach ($this->routes->all() as $configurator){ |
|
| 64 | 64 | $configurator->core($core); |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | return $this; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - public function middleware(MiddlewareInterface|string|array $middleware): self |
|
| 70 | + public function middleware(MiddlewareInterface | string | array $middleware): self |
|
| 71 | 71 | { |
| 72 | - foreach ($this->routes->all() as $configurator) { |
|
| 72 | + foreach ($this->routes->all() as $configurator){ |
|
| 73 | 73 | $configurator->middleware($middleware); |
| 74 | 74 | } |
| 75 | 75 | |
@@ -33,7 +33,8 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | public function defaults(array $defaults): self |
| 35 | 35 | { |
| 36 | - foreach ($this->routes->all() as $configurator) { |
|
| 36 | + foreach ($this->routes->all() as $configurator) |
|
| 37 | + { |
|
| 37 | 38 | $configurator->defaults($defaults); |
| 38 | 39 | } |
| 39 | 40 | |
@@ -42,7 +43,8 @@ discard block |
||
| 42 | 43 | |
| 43 | 44 | public function group(string $group): self |
| 44 | 45 | { |
| 45 | - foreach ($this->routes->all() as $configurator) { |
|
| 46 | + foreach ($this->routes->all() as $configurator) |
|
| 47 | + { |
|
| 46 | 48 | $configurator->group($group); |
| 47 | 49 | } |
| 48 | 50 | |
@@ -51,7 +53,8 @@ discard block |
||
| 51 | 53 | |
| 52 | 54 | public function prefix(string $prefix): self |
| 53 | 55 | { |
| 54 | - foreach ($this->routes->all() as $configurator) { |
|
| 56 | + foreach ($this->routes->all() as $configurator) |
|
| 57 | + { |
|
| 55 | 58 | $configurator->prefix($prefix); |
| 56 | 59 | } |
| 57 | 60 | |
@@ -60,7 +63,8 @@ discard block |
||
| 60 | 63 | |
| 61 | 64 | public function core(CoreInterface $core): self |
| 62 | 65 | { |
| 63 | - foreach ($this->routes->all() as $configurator) { |
|
| 66 | + foreach ($this->routes->all() as $configurator) |
|
| 67 | + { |
|
| 64 | 68 | $configurator->core($core); |
| 65 | 69 | } |
| 66 | 70 | |
@@ -69,7 +73,8 @@ discard block |
||
| 69 | 73 | |
| 70 | 74 | public function middleware(MiddlewareInterface|string|array $middleware): self |
| 71 | 75 | { |
| 72 | - foreach ($this->routes->all() as $configurator) { |
|
| 76 | + foreach ($this->routes->all() as $configurator) |
|
| 77 | + { |
|
| 73 | 78 | $configurator->middleware($middleware); |
| 74 | 79 | } |
| 75 | 80 | |
@@ -14,19 +14,19 @@ |
||
| 14 | 14 | public function __construct( |
| 15 | 15 | private readonly RouteCollection $collection, |
| 16 | 16 | private readonly LoaderInterface $loader |
| 17 | - ) { |
|
| 17 | + ){ |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - public function import(string|array $resource, string $type = null): ImportConfigurator |
|
| 20 | + public function import(string | array $resource, string $type = null): ImportConfigurator |
|
| 21 | 21 | { |
| 22 | 22 | $imported = $this->loader->load($resource, $type) ?: []; |
| 23 | 23 | |
| 24 | - if (!\is_array($imported)) { |
|
| 24 | + if (!\is_array($imported)){ |
|
| 25 | 25 | return new ImportConfigurator($this->collection, $imported); |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | $mergedCollection = new RouteCollection(); |
| 29 | - foreach ($imported as $subCollection) { |
|
| 29 | + foreach ($imported as $subCollection){ |
|
| 30 | 30 | $mergedCollection->addCollection($subCollection); |
| 31 | 31 | } |
| 32 | 32 | |
@@ -21,12 +21,14 @@ |
||
| 21 | 21 | { |
| 22 | 22 | $imported = $this->loader->load($resource, $type) ?: []; |
| 23 | 23 | |
| 24 | - if (!\is_array($imported)) { |
|
| 24 | + if (!\is_array($imported)) |
|
| 25 | + { |
|
| 25 | 26 | return new ImportConfigurator($this->collection, $imported); |
| 26 | 27 | } |
| 27 | 28 | |
| 28 | 29 | $mergedCollection = new RouteCollection(); |
| 29 | - foreach ($imported as $subCollection) { |
|
| 30 | + foreach ($imported as $subCollection) |
|
| 31 | + { |
|
| 30 | 32 | $mergedCollection->addCollection($subCollection); |
| 31 | 33 | } |
| 32 | 34 | |
@@ -31,12 +31,12 @@ discard block |
||
| 31 | 31 | private readonly string $name, |
| 32 | 32 | private readonly string $pattern, |
| 33 | 33 | private readonly RouteCollection $collection |
| 34 | - ) { |
|
| 34 | + ){ |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | public function __destruct() |
| 38 | 38 | { |
| 39 | - if ($this->target === null) { |
|
| 39 | + if ($this->target === null){ |
|
| 40 | 40 | throw new TargetException( |
| 41 | 41 | \sprintf('The [%s] route has no defined target. Call one of: `controller`, `action`, |
| 42 | 42 | `namespaced`, `groupControllers`, `callable`, `handler` methods.', $this->name) |
@@ -87,21 +87,21 @@ discard block |
||
| 87 | 87 | return $this; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - public function action(string $controller, string|array $action, int $options = 0): self |
|
| 90 | + public function action(string $controller, string | array $action, int $options = 0): self |
|
| 91 | 91 | { |
| 92 | 92 | $this->target = new Action($controller, $action, $options); |
| 93 | 93 | |
| 94 | 94 | return $this; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - public function callable(array|\Closure $callable): self |
|
| 97 | + public function callable(array | \Closure $callable): self |
|
| 98 | 98 | { |
| 99 | 99 | $this->target = $callable; |
| 100 | 100 | |
| 101 | 101 | return $this; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - public function handler(TargetInterface|string $target): self |
|
| 104 | + public function handler(TargetInterface | string $target): self |
|
| 105 | 105 | { |
| 106 | 106 | $this->target = $target; |
| 107 | 107 | |
@@ -136,9 +136,9 @@ discard block |
||
| 136 | 136 | return $this; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - public function middleware(MiddlewareInterface|string|array $middleware): self |
|
| 139 | + public function middleware(MiddlewareInterface | string | array $middleware): self |
|
| 140 | 140 | { |
| 141 | - if (!\is_array($middleware)) { |
|
| 141 | + if (!\is_array($middleware)){ |
|
| 142 | 142 | $middleware = [$middleware]; |
| 143 | 143 | } |
| 144 | 144 | |
@@ -147,9 +147,9 @@ discard block |
||
| 147 | 147 | return $this; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - public function methods(string|array $methods): self |
|
| 150 | + public function methods(string | array $methods): self |
|
| 151 | 151 | { |
| 152 | - $this->methods = (array) $methods; |
|
| 152 | + $this->methods = (array)$methods; |
|
| 153 | 153 | |
| 154 | 154 | return $this; |
| 155 | 155 | } |
@@ -36,7 +36,8 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | public function __destruct() |
| 38 | 38 | { |
| 39 | - if ($this->target === null) { |
|
| 39 | + if ($this->target === null) |
|
| 40 | + { |
|
| 40 | 41 | throw new TargetException( |
| 41 | 42 | \sprintf('The [%s] route has no defined target. Call one of: `controller`, `action`, |
| 42 | 43 | `namespaced`, `groupControllers`, `callable`, `handler` methods.', $this->name) |
@@ -138,7 +139,8 @@ discard block |
||
| 138 | 139 | |
| 139 | 140 | public function middleware(MiddlewareInterface|string|array $middleware): self |
| 140 | 141 | { |
| 141 | - if (!\is_array($middleware)) { |
|
| 142 | + if (!\is_array($middleware)) |
|
| 143 | + { |
|
| 142 | 144 | $middleware = [$middleware]; |
| 143 | 145 | } |
| 144 | 146 | |
@@ -10,12 +10,12 @@ |
||
| 10 | 10 | { |
| 11 | 11 | public function __construct( |
| 12 | 12 | private readonly LoaderRegistryInterface $registry |
| 13 | - ) { |
|
| 13 | + ){ |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | public function load(mixed $resource, string $type = null): mixed |
| 17 | 17 | { |
| 18 | - if (false === $loader = $this->registry->resolve($resource, $type)) { |
|
| 18 | + if (false === $loader = $this->registry->resolve($resource, $type)){ |
|
| 19 | 19 | throw new LoaderLoadException(\sprintf('Loader for type [%s] not found.', $type)); |
| 20 | 20 | } |
| 21 | 21 | |
@@ -15,7 +15,8 @@ |
||
| 15 | 15 | |
| 16 | 16 | public function load(mixed $resource, string $type = null): mixed |
| 17 | 17 | { |
| 18 | - if (false === $loader = $this->registry->resolve($resource, $type)) { |
|
| 18 | + if (false === $loader = $this->registry->resolve($resource, $type)) |
|
| 19 | + { |
|
| 19 | 20 | throw new LoaderLoadException(\sprintf('Loader for type [%s] not found.', $type)); |
| 20 | 21 | } |
| 21 | 22 | |
@@ -11,5 +11,5 @@ |
||
| 11 | 11 | * |
| 12 | 12 | * @param string|null $type The resource type or null if unknown |
| 13 | 13 | */ |
| 14 | - public function resolve(mixed $resource, string $type = null): LoaderInterface|false; |
|
| 14 | + public function resolve(mixed $resource, string $type = null): LoaderInterface | false; |
|
| 15 | 15 | } |
@@ -16,15 +16,15 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | public function __construct(array $loaders = []) |
| 18 | 18 | { |
| 19 | - foreach ($loaders as $loader) { |
|
| 19 | + foreach ($loaders as $loader){ |
|
| 20 | 20 | $this->addLoader($loader); |
| 21 | 21 | } |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - public function resolve(mixed $resource, string $type = null): LoaderInterface|false |
|
| 24 | + public function resolve(mixed $resource, string $type = null): LoaderInterface | false |
|
| 25 | 25 | { |
| 26 | - foreach ($this->loaders as $loader) { |
|
| 27 | - if ($loader->supports($resource, $type)) { |
|
| 26 | + foreach ($this->loaders as $loader){ |
|
| 27 | + if ($loader->supports($resource, $type)){ |
|
| 28 | 28 | return $loader; |
| 29 | 29 | } |
| 30 | 30 | } |
@@ -16,15 +16,18 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | public function __construct(array $loaders = []) |
| 18 | 18 | { |
| 19 | - foreach ($loaders as $loader) { |
|
| 19 | + foreach ($loaders as $loader) |
|
| 20 | + { |
|
| 20 | 21 | $this->addLoader($loader); |
| 21 | 22 | } |
| 22 | 23 | } |
| 23 | 24 | |
| 24 | 25 | public function resolve(mixed $resource, string $type = null): LoaderInterface|false |
| 25 | 26 | { |
| 26 | - foreach ($this->loaders as $loader) { |
|
| 27 | - if ($loader->supports($resource, $type)) { |
|
| 27 | + foreach ($this->loaders as $loader) |
|
| 28 | + { |
|
| 29 | + if ($loader->supports($resource, $type)) |
|
| 30 | + { |
|
| 28 | 31 | return $loader; |
| 29 | 32 | } |
| 30 | 33 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | public function __construct( |
| 17 | 17 | private readonly FactoryInterface $factory, |
| 18 | 18 | private readonly ResolverInterface $resolver, |
| 19 | - ) { |
|
| 19 | + ){ |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -24,11 +24,11 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | public function load(mixed $resource, string $type = null): RouteCollection |
| 26 | 26 | { |
| 27 | - if (!\file_exists($resource)) { |
|
| 27 | + if (!\file_exists($resource)){ |
|
| 28 | 28 | throw new LoaderLoadException(\sprintf('File [%s] does not exist.', $resource)); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - $load = static function (string $path) { |
|
| 31 | + $load = static function (string $path){ |
|
| 32 | 32 | return include $path; |
| 33 | 33 | }; |
| 34 | 34 | |
@@ -24,11 +24,13 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | public function load(mixed $resource, string $type = null): RouteCollection |
| 26 | 26 | { |
| 27 | - if (!\file_exists($resource)) { |
|
| 27 | + if (!\file_exists($resource)) |
|
| 28 | + { |
|
| 28 | 29 | throw new LoaderLoadException(\sprintf('File [%s] does not exist.', $resource)); |
| 29 | 30 | } |
| 30 | 31 | |
| 31 | - $load = static function (string $path) { |
|
| 32 | + $load = static function (string $path) |
|
| 33 | + { |
|
| 32 | 34 | return include $path; |
| 33 | 35 | }; |
| 34 | 36 | |