@@ -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 |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | |
14 | 14 | public function __clone() |
15 | 15 | { |
16 | - foreach ($this->routes as $name => $route) { |
|
16 | + foreach ($this->routes as $name => $route){ |
|
17 | 17 | $this->routes[$name] = clone $route; |
18 | 18 | } |
19 | 19 | } |
@@ -72,16 +72,16 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @param string|string[] $name The route name or an array of route names |
74 | 74 | */ |
75 | - public function remove(string|array $name) |
|
75 | + public function remove(string | array $name) |
|
76 | 76 | { |
77 | - foreach ((array) $name as $n) { |
|
77 | + foreach ((array)$name as $n){ |
|
78 | 78 | unset($this->routes[$n]); |
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
82 | 82 | public function addCollection(self $collection) |
83 | 83 | { |
84 | - foreach ($collection->all() as $name => $route) { |
|
84 | + foreach ($collection->all() as $name => $route){ |
|
85 | 85 | $this->routes[$name] = $route; |
86 | 86 | } |
87 | 87 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function group(string $group) |
93 | 93 | { |
94 | - foreach ($this->routes as $route) { |
|
94 | + foreach ($this->routes as $route){ |
|
95 | 95 | $route->group($group); |
96 | 96 | } |
97 | 97 | } |
@@ -13,7 +13,8 @@ discard block |
||
13 | 13 | |
14 | 14 | public function __clone() |
15 | 15 | { |
16 | - foreach ($this->routes as $name => $route) { |
|
16 | + foreach ($this->routes as $name => $route) |
|
17 | + { |
|
17 | 18 | $this->routes[$name] = clone $route; |
18 | 19 | } |
19 | 20 | } |
@@ -74,14 +75,16 @@ discard block |
||
74 | 75 | */ |
75 | 76 | public function remove(string|array $name) |
76 | 77 | { |
77 | - foreach ((array) $name as $n) { |
|
78 | + foreach ((array) $name as $n) |
|
79 | + { |
|
78 | 80 | unset($this->routes[$n]); |
79 | 81 | } |
80 | 82 | } |
81 | 83 | |
82 | 84 | public function addCollection(self $collection) |
83 | 85 | { |
84 | - foreach ($collection->all() as $name => $route) { |
|
86 | + foreach ($collection->all() as $name => $route) |
|
87 | + { |
|
85 | 88 | $this->routes[$name] = $route; |
86 | 89 | } |
87 | 90 | } |
@@ -91,7 +94,8 @@ discard block |
||
91 | 94 | */ |
92 | 95 | public function group(string $group) |
93 | 96 | { |
94 | - foreach ($this->routes as $route) { |
|
97 | + foreach ($this->routes as $route) |
|
98 | + { |
|
95 | 99 | $route->group($group); |
96 | 100 | } |
97 | 101 | } |
@@ -19,9 +19,9 @@ |
||
19 | 19 | */ |
20 | 20 | public function withVerbs(string ...$verbs): RouteInterface |
21 | 21 | { |
22 | - foreach ($verbs as &$verb) { |
|
22 | + foreach ($verbs as &$verb){ |
|
23 | 23 | $verb = \strtoupper($verb); |
24 | - if (!\in_array($verb, RouteInterface::VERBS, true)) { |
|
24 | + if (!\in_array($verb, RouteInterface::VERBS, true)){ |
|
25 | 25 | throw new RouteException(\sprintf('Invalid HTTP verb `%s`', $verb)); |
26 | 26 | } |
27 | 27 |
@@ -19,9 +19,11 @@ |
||
19 | 19 | */ |
20 | 20 | public function withVerbs(string ...$verbs): RouteInterface |
21 | 21 | { |
22 | - foreach ($verbs as &$verb) { |
|
22 | + foreach ($verbs as &$verb) |
|
23 | + { |
|
23 | 24 | $verb = \strtoupper($verb); |
24 | - if (!\in_array($verb, RouteInterface::VERBS, true)) { |
|
25 | + if (!\in_array($verb, RouteInterface::VERBS, true)) |
|
26 | + { |
|
25 | 27 | throw new RouteException(\sprintf('Invalid HTTP verb `%s`', $verb)); |
26 | 28 | } |
27 | 29 |
@@ -42,16 +42,16 @@ discard block |
||
42 | 42 | $route = clone $this; |
43 | 43 | |
44 | 44 | // array fallback |
45 | - if (\count($middleware) === 1 && \is_array($middleware[0])) { |
|
45 | + if (\count($middleware) === 1 && \is_array($middleware[0])){ |
|
46 | 46 | $middleware = $middleware[0]; |
47 | 47 | } |
48 | 48 | |
49 | 49 | /** @var MiddlewareType[] $middleware */ |
50 | - foreach ($middleware as $item) { |
|
50 | + foreach ($middleware as $item){ |
|
51 | 51 | $route->middleware[] = $item; |
52 | 52 | } |
53 | 53 | |
54 | - if ($route->pipeline !== null) { |
|
54 | + if ($route->pipeline !== null){ |
|
55 | 55 | $route->pipeline = $route->makePipeline(); |
56 | 56 | } |
57 | 57 | |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | */ |
76 | 76 | protected function makePipeline(): Pipeline |
77 | 77 | { |
78 | - try { |
|
78 | + try{ |
|
79 | 79 | return $this->container |
80 | 80 | ->get(PipelineFactory::class) |
81 | 81 | ->createWithMiddleware($this->middleware); |
82 | - } catch (ContainerExceptionInterface $e) { |
|
82 | + }catch (ContainerExceptionInterface $e){ |
|
83 | 83 | throw new RouteException($e->getMessage(), $e->getCode(), $e); |
84 | 84 | } |
85 | 85 | } |
@@ -42,16 +42,19 @@ discard block |
||
42 | 42 | $route = clone $this; |
43 | 43 | |
44 | 44 | // array fallback |
45 | - if (\count($middleware) === 1 && \is_array($middleware[0])) { |
|
45 | + if (\count($middleware) === 1 && \is_array($middleware[0])) |
|
46 | + { |
|
46 | 47 | $middleware = $middleware[0]; |
47 | 48 | } |
48 | 49 | |
49 | 50 | /** @var MiddlewareType[] $middleware */ |
50 | - foreach ($middleware as $item) { |
|
51 | + foreach ($middleware as $item) |
|
52 | + { |
|
51 | 53 | $route->middleware[] = $item; |
52 | 54 | } |
53 | 55 | |
54 | - if ($route->pipeline !== null) { |
|
56 | + if ($route->pipeline !== null) |
|
57 | + { |
|
55 | 58 | $route->pipeline = $route->makePipeline(); |
56 | 59 | } |
57 | 60 | |
@@ -75,11 +78,14 @@ discard block |
||
75 | 78 | */ |
76 | 79 | protected function makePipeline(): Pipeline |
77 | 80 | { |
78 | - try { |
|
81 | + try |
|
82 | + { |
|
79 | 83 | return $this->container |
80 | 84 | ->get(PipelineFactory::class) |
81 | 85 | ->createWithMiddleware($this->middleware); |
82 | - } catch (ContainerExceptionInterface $e) { |
|
86 | + } |
|
87 | + catch (ContainerExceptionInterface $e) |
|
88 | + { |
|
83 | 89 | throw new RouteException($e->getMessage(), $e->getCode(), $e); |
84 | 90 | } |
85 | 91 | } |
@@ -10,6 +10,6 @@ |
||
10 | 10 | { |
11 | 11 | public function __construct( |
12 | 12 | public readonly ServerRequestInterface $request |
13 | - ) { |
|
13 | + ){ |
|
14 | 14 | } |
15 | 15 | } |
@@ -12,6 +12,6 @@ |
||
12 | 12 | public function __construct( |
13 | 13 | public readonly ServerRequestInterface $request, |
14 | 14 | public readonly RouteInterface $route, |
15 | - ) { |
|
15 | + ){ |
|
16 | 16 | } |
17 | 17 | } |
@@ -8,7 +8,7 @@ |
||
8 | 8 | { |
9 | 9 | public function __construct( |
10 | 10 | private readonly string $value |
11 | - ) { |
|
11 | + ){ |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | public function __toString(): string |