@@ -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 |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | public function __construct( |
18 | 18 | private readonly ContainerInterface $container, |
19 | 19 | private readonly FactoryInterface $factory |
20 | - ) { |
|
20 | + ){ |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | /** |
@@ -26,27 +26,27 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function createWithMiddleware(array $middleware): Pipeline |
28 | 28 | { |
29 | - if (\count($middleware) === 1 && $middleware[0] instanceof Pipeline) { |
|
29 | + if (\count($middleware) === 1 && $middleware[0] instanceof Pipeline){ |
|
30 | 30 | return $middleware[0]; |
31 | 31 | } |
32 | 32 | |
33 | 33 | $pipeline = $this->factory->make(Pipeline::class); |
34 | 34 | \assert($pipeline instanceof Pipeline); |
35 | 35 | |
36 | - foreach ($middleware as $item) { |
|
37 | - if ($item instanceof MiddlewareInterface) { |
|
36 | + foreach ($middleware as $item){ |
|
37 | + if ($item instanceof MiddlewareInterface){ |
|
38 | 38 | $pipeline->pushMiddleware($item); |
39 | - } elseif (\is_string($item)) { |
|
39 | + } elseif (\is_string($item)){ |
|
40 | 40 | $item = $this->container->get($item); |
41 | 41 | \assert($item instanceof MiddlewareInterface); |
42 | 42 | |
43 | 43 | $pipeline->pushMiddleware($item); |
44 | - } elseif ($item instanceof Autowire) { |
|
44 | + } elseif ($item instanceof Autowire){ |
|
45 | 45 | $item = $item->resolve($this->factory); |
46 | 46 | \assert($item instanceof MiddlewareInterface); |
47 | 47 | |
48 | 48 | $pipeline->pushMiddleware($item); |
49 | - } else { |
|
49 | + }else{ |
|
50 | 50 | $name = get_debug_type($item); |
51 | 51 | throw new RouteException(\sprintf('Invalid middleware `%s`', $name)); |
52 | 52 | } |
@@ -26,27 +26,36 @@ |
||
26 | 26 | */ |
27 | 27 | public function createWithMiddleware(array $middleware): Pipeline |
28 | 28 | { |
29 | - if (\count($middleware) === 1 && $middleware[0] instanceof Pipeline) { |
|
29 | + if (\count($middleware) === 1 && $middleware[0] instanceof Pipeline) |
|
30 | + { |
|
30 | 31 | return $middleware[0]; |
31 | 32 | } |
32 | 33 | |
33 | 34 | $pipeline = $this->factory->make(Pipeline::class); |
34 | 35 | \assert($pipeline instanceof Pipeline); |
35 | 36 | |
36 | - foreach ($middleware as $item) { |
|
37 | - if ($item instanceof MiddlewareInterface) { |
|
37 | + foreach ($middleware as $item) |
|
38 | + { |
|
39 | + if ($item instanceof MiddlewareInterface) |
|
40 | + { |
|
38 | 41 | $pipeline->pushMiddleware($item); |
39 | - } elseif (\is_string($item)) { |
|
42 | + } |
|
43 | + elseif (\is_string($item)) |
|
44 | + { |
|
40 | 45 | $item = $this->container->get($item); |
41 | 46 | \assert($item instanceof MiddlewareInterface); |
42 | 47 | |
43 | 48 | $pipeline->pushMiddleware($item); |
44 | - } elseif ($item instanceof Autowire) { |
|
49 | + } |
|
50 | + elseif ($item instanceof Autowire) |
|
51 | + { |
|
45 | 52 | $item = $item->resolve($this->factory); |
46 | 53 | \assert($item instanceof MiddlewareInterface); |
47 | 54 | |
48 | 55 | $pipeline->pushMiddleware($item); |
49 | - } else { |
|
56 | + } |
|
57 | + else |
|
58 | + { |
|
50 | 59 | $name = get_debug_type($item); |
51 | 60 | throw new RouteException(\sprintf('Invalid middleware `%s`', $name)); |
52 | 61 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | public function __construct( |
21 | 21 | protected string $pattern, |
22 | 22 | array $defaults = [] |
23 | - ) { |
|
23 | + ){ |
|
24 | 24 | $this->defaults = $defaults; |
25 | 25 | } |
26 | 26 | |
@@ -39,12 +39,12 @@ discard block |
||
39 | 39 | |
40 | 40 | public function match(Request $request): ?static |
41 | 41 | { |
42 | - if (!\in_array(\strtoupper($request->getMethod()), $this->getVerbs(), true)) { |
|
42 | + if (!\in_array(\strtoupper($request->getMethod()), $this->getVerbs(), true)){ |
|
43 | 43 | return null; |
44 | 44 | } |
45 | 45 | |
46 | 46 | $matches = $this->uriHandler->match($request->getUri(), $this->defaults); |
47 | - if ($matches === null) { |
|
47 | + if ($matches === null){ |
|
48 | 48 | return null; |
49 | 49 | } |
50 | 50 |
@@ -39,12 +39,14 @@ |
||
39 | 39 | |
40 | 40 | public function match(Request $request): ?static |
41 | 41 | { |
42 | - if (!\in_array(\strtoupper($request->getMethod()), $this->getVerbs(), true)) { |
|
42 | + if (!\in_array(\strtoupper($request->getMethod()), $this->getVerbs(), true)) |
|
43 | + { |
|
43 | 44 | return null; |
44 | 45 | } |
45 | 46 | |
46 | 47 | $matches = $this->uriHandler->match($request->getUri(), $this->defaults); |
47 | - if ($matches === null) { |
|
48 | + if ($matches === null) |
|
49 | + { |
|
48 | 50 | return null; |
49 | 51 | } |
50 | 52 |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function __construct( |
52 | 52 | string $pattern, |
53 | - string|callable|RequestHandlerInterface|TargetInterface $target, |
|
53 | + string | callable | RequestHandlerInterface | TargetInterface $target, |
|
54 | 54 | array $defaults = [] |
55 | - ) { |
|
55 | + ){ |
|
56 | 56 | parent::__construct( |
57 | 57 | $pattern, |
58 | 58 | $target instanceof TargetInterface |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | public function withUriHandler(UriHandler $uriHandler): static |
67 | 67 | { |
68 | 68 | $route = parent::withUriHandler($uriHandler); |
69 | - if ($this->target instanceof TargetInterface) { |
|
69 | + if ($this->target instanceof TargetInterface){ |
|
70 | 70 | $route->uriHandler = $route->uriHandler->withConstrains( |
71 | 71 | $this->target->getConstrains(), |
72 | 72 | $this->defaults |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | $route = clone $this; |
85 | 85 | $route->container = $container; |
86 | 86 | |
87 | - if ($route->target instanceof TargetInterface) { |
|
87 | + if ($route->target instanceof TargetInterface){ |
|
88 | 88 | $route->target = clone $route->target; |
89 | 89 | } |
90 | 90 | |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | */ |
112 | 112 | public function handle(ServerRequestInterface $request): ResponseInterface |
113 | 113 | { |
114 | - if (empty($this->requestHandler)) { |
|
114 | + if (empty($this->requestHandler)){ |
|
115 | 115 | $this->requestHandler = $this->requestHandler(); |
116 | 116 | } |
117 | 117 | |
@@ -126,28 +126,28 @@ discard block |
||
126 | 126 | */ |
127 | 127 | protected function requestHandler(): RequestHandlerInterface |
128 | 128 | { |
129 | - if (!$this->hasContainer()) { |
|
129 | + if (!$this->hasContainer()){ |
|
130 | 130 | throw new RouteException('Unable to configure route pipeline without associated container'); |
131 | 131 | } |
132 | 132 | |
133 | - if ($this->target instanceof TargetInterface) { |
|
134 | - try { |
|
133 | + if ($this->target instanceof TargetInterface){ |
|
134 | + try{ |
|
135 | 135 | return $this->target->getHandler($this->container, $this->matches); |
136 | - } catch (TargetException $e) { |
|
136 | + }catch (TargetException $e){ |
|
137 | 137 | throw new RouteException('Invalid target resolution', $e->getCode(), $e); |
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
141 | - if ($this->target instanceof RequestHandlerInterface) { |
|
141 | + if ($this->target instanceof RequestHandlerInterface){ |
|
142 | 142 | return $this->target; |
143 | 143 | } |
144 | 144 | |
145 | - try { |
|
145 | + try{ |
|
146 | 146 | $target = \is_string($this->target) |
147 | 147 | ? $this->container->get($this->target) |
148 | 148 | : $this->target; |
149 | 149 | |
150 | - if ($target instanceof RequestHandlerInterface) { |
|
150 | + if ($target instanceof RequestHandlerInterface){ |
|
151 | 151 | return $target; |
152 | 152 | } |
153 | 153 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | $target, |
156 | 156 | $this->container->get(ResponseFactoryInterface::class) |
157 | 157 | ); |
158 | - } catch (ContainerExceptionInterface $e) { |
|
158 | + }catch (ContainerExceptionInterface $e){ |
|
159 | 159 | throw new RouteException($e->getMessage(), $e->getCode(), $e); |
160 | 160 | } |
161 | 161 | } |
@@ -66,7 +66,8 @@ discard block |
||
66 | 66 | public function withUriHandler(UriHandler $uriHandler): static |
67 | 67 | { |
68 | 68 | $route = parent::withUriHandler($uriHandler); |
69 | - if ($this->target instanceof TargetInterface) { |
|
69 | + if ($this->target instanceof TargetInterface) |
|
70 | + { |
|
70 | 71 | $route->uriHandler = $route->uriHandler->withConstrains( |
71 | 72 | $this->target->getConstrains(), |
72 | 73 | $this->defaults |
@@ -84,7 +85,8 @@ discard block |
||
84 | 85 | $route = clone $this; |
85 | 86 | $route->container = $container; |
86 | 87 | |
87 | - if ($route->target instanceof TargetInterface) { |
|
88 | + if ($route->target instanceof TargetInterface) |
|
89 | + { |
|
88 | 90 | $route->target = clone $route->target; |
89 | 91 | } |
90 | 92 | |
@@ -111,7 +113,8 @@ discard block |
||
111 | 113 | */ |
112 | 114 | public function handle(ServerRequestInterface $request): ResponseInterface |
113 | 115 | { |
114 | - if (empty($this->requestHandler)) { |
|
116 | + if (empty($this->requestHandler)) |
|
117 | + { |
|
115 | 118 | $this->requestHandler = $this->requestHandler(); |
116 | 119 | } |
117 | 120 | |
@@ -126,28 +129,36 @@ discard block |
||
126 | 129 | */ |
127 | 130 | protected function requestHandler(): RequestHandlerInterface |
128 | 131 | { |
129 | - if (!$this->hasContainer()) { |
|
132 | + if (!$this->hasContainer()) |
|
133 | + { |
|
130 | 134 | throw new RouteException('Unable to configure route pipeline without associated container'); |
131 | 135 | } |
132 | 136 | |
133 | - if ($this->target instanceof TargetInterface) { |
|
134 | - try { |
|
137 | + if ($this->target instanceof TargetInterface) |
|
138 | + { |
|
139 | + try |
|
140 | + { |
|
135 | 141 | return $this->target->getHandler($this->container, $this->matches); |
136 | - } catch (TargetException $e) { |
|
142 | + } |
|
143 | + catch (TargetException $e) |
|
144 | + { |
|
137 | 145 | throw new RouteException('Invalid target resolution', $e->getCode(), $e); |
138 | 146 | } |
139 | 147 | } |
140 | 148 | |
141 | - if ($this->target instanceof RequestHandlerInterface) { |
|
149 | + if ($this->target instanceof RequestHandlerInterface) |
|
150 | + { |
|
142 | 151 | return $this->target; |
143 | 152 | } |
144 | 153 | |
145 | - try { |
|
154 | + try |
|
155 | + { |
|
146 | 156 | $target = \is_string($this->target) |
147 | 157 | ? $this->container->get($this->target) |
148 | 158 | : $this->target; |
149 | 159 | |
150 | - if ($target instanceof RequestHandlerInterface) { |
|
160 | + if ($target instanceof RequestHandlerInterface) |
|
161 | + { |
|
151 | 162 | return $target; |
152 | 163 | } |
153 | 164 | |
@@ -155,7 +166,9 @@ discard block |
||
155 | 166 | $target, |
156 | 167 | $this->container->get(ResponseFactoryInterface::class) |
157 | 168 | ); |
158 | - } catch (ContainerExceptionInterface $e) { |
|
169 | + } |
|
170 | + catch (ContainerExceptionInterface $e) |
|
171 | + { |
|
159 | 172 | throw new RouteException($e->getMessage(), $e->getCode(), $e); |
160 | 173 | } |
161 | 174 | } |
@@ -12,8 +12,8 @@ |
||
12 | 12 | private readonly UriInterface $uri, |
13 | 13 | int $code = 0, |
14 | 14 | \Throwable $previous = null |
15 | - ) { |
|
16 | - parent::__construct(\sprintf('Unable to route `%s`.', (string) $uri), $code, $previous); |
|
15 | + ){ |
|
16 | + parent::__construct(\sprintf('Unable to route `%s`.', (string)$uri), $code, $previous); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | public function getUri(): UriInterface |