@@ -28,7 +28,7 @@ |
||
28 | 28 | * @param non-empty-string|int $code |
29 | 29 | * @param non-empty-string|null $description |
30 | 30 | */ |
31 | - public function setStatus(string|int $code, ?string $description = null): self; |
|
31 | + public function setStatus(string | int $code, ?string $description = null): self; |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * Get the current span status. |
@@ -18,21 +18,21 @@ discard block |
||
18 | 18 | */ |
19 | 19 | abstract public function bucket(?string $name = null): BucketInterface; |
20 | 20 | |
21 | - public function getContents(string|\Stringable $id): string |
|
21 | + public function getContents(string | \Stringable $id): string |
|
22 | 22 | { |
23 | 23 | [$name, $pathname] = $this->parseUri($id); |
24 | 24 | |
25 | 25 | return $this->bucket($name)->getContents($pathname); |
26 | 26 | } |
27 | 27 | |
28 | - public function getStream(string|\Stringable $id) |
|
28 | + public function getStream(string | \Stringable $id) |
|
29 | 29 | { |
30 | 30 | [$name, $pathname] = $this->parseUri($id); |
31 | 31 | |
32 | 32 | return $this->bucket($name)->getStream($pathname); |
33 | 33 | } |
34 | 34 | |
35 | - public function exists(string|\Stringable $id): bool |
|
35 | + public function exists(string | \Stringable $id): bool |
|
36 | 36 | { |
37 | 37 | [$name, $pathname] = $this->parseUri($id); |
38 | 38 | |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * @return int<0, max> |
44 | 44 | */ |
45 | - public function getLastModified(string|\Stringable $id): int |
|
45 | + public function getLastModified(string | \Stringable $id): int |
|
46 | 46 | { |
47 | 47 | [$name, $pathname] = $this->parseUri($id); |
48 | 48 | |
@@ -52,14 +52,14 @@ discard block |
||
52 | 52 | /** |
53 | 53 | * @return int<0, max> |
54 | 54 | */ |
55 | - public function getSize(string|\Stringable $id): int |
|
55 | + public function getSize(string | \Stringable $id): int |
|
56 | 56 | { |
57 | 57 | [$name, $pathname] = $this->parseUri($id); |
58 | 58 | |
59 | 59 | return $this->bucket($name)->getSize($pathname); |
60 | 60 | } |
61 | 61 | |
62 | - public function getMimeType(string|\Stringable $id): string |
|
62 | + public function getMimeType(string | \Stringable $id): string |
|
63 | 63 | { |
64 | 64 | [$name, $pathname] = $this->parseUri($id); |
65 | 65 | |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * @return Visibility::VISIBILITY_* |
71 | 71 | */ |
72 | 72 | #[ExpectedValues(valuesFromClass: Visibility::class)] |
73 | - public function getVisibility(string|\Stringable $id): string |
|
73 | + public function getVisibility(string | \Stringable $id): string |
|
74 | 74 | { |
75 | 75 | [$name, $pathname] = $this->parseUri($id); |
76 | 76 | |
@@ -80,5 +80,5 @@ discard block |
||
80 | 80 | /** |
81 | 81 | * {@see Storage::parseUri()} |
82 | 82 | */ |
83 | - abstract protected function parseUri(string|\Stringable $uri, bool $withScheme = true): array; |
|
83 | + abstract protected function parseUri(string | \Stringable $uri, bool $withScheme = true): array; |
|
84 | 84 | } |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | { |
22 | 22 | $root = self::makeContainer(); |
23 | 23 | |
24 | - $obj = $root->runScoped(static function (Container $c1) { |
|
25 | - $obj = $c1->runScoped(static function (Container $c2) { |
|
24 | + $obj = $root->runScoped(static function (Container $c1){ |
|
25 | + $obj = $c1->runScoped(static function (Container $c2){ |
|
26 | 26 | $obj = $c2->get(AttrScopeFooFinalize::class); |
27 | 27 | |
28 | 28 | self::assertFalse($obj->finalized); |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | self::expectException(FinalizersException::class); |
125 | 125 | self::expectExceptionMessage('An exception has been thrown during finalization of the scope `foo`'); |
126 | 126 | |
127 | - try { |
|
127 | + try{ |
|
128 | 128 | $root->runScoped(static function (Container $c1): void { |
129 | 129 | $obj = $c1->get(AttrScopeFooFinalize::class); |
130 | 130 | $obj->throwException = true; |
131 | 131 | }, name: 'foo'); |
132 | - } catch (FinalizersException $e) { |
|
132 | + }catch (FinalizersException $e){ |
|
133 | 133 | self::assertSame('foo', $e->getScope()); |
134 | 134 | self::assertCount(1, $e->getExceptions()); |
135 | 135 | // Contains the message from the inner exception. |
@@ -153,13 +153,13 @@ discard block |
||
153 | 153 | self::expectException(FinalizersException::class); |
154 | 154 | self::expectExceptionMessage('3 exceptions have been thrown during finalization of the scope `foo`'); |
155 | 155 | |
156 | - try { |
|
156 | + try{ |
|
157 | 157 | $root->runScoped(static function (Container $c1): void { |
158 | 158 | $c1->get(AttrScopeFooFinalize::class)->throwException = true; |
159 | 159 | $c1->get(AttrScopeFooFinalize::class)->throwException = true; |
160 | 160 | $c1->get(AttrScopeFooFinalize::class)->throwException = true; |
161 | 161 | }, name: 'foo'); |
162 | - } catch (FinalizersException $e) { |
|
162 | + }catch (FinalizersException $e){ |
|
163 | 163 | self::assertSame('foo', $e->getScope()); |
164 | 164 | self::assertCount(3, $e->getExceptions()); |
165 | 165 | // Contains the message from the inner exception. |
@@ -21,8 +21,10 @@ discard block |
||
21 | 21 | { |
22 | 22 | $root = self::makeContainer(); |
23 | 23 | |
24 | - $obj = $root->runScoped(static function (Container $c1) { |
|
25 | - $obj = $c1->runScoped(static function (Container $c2) { |
|
24 | + $obj = $root->runScoped(static function (Container $c1) |
|
25 | + { |
|
26 | + $obj = $c1->runScoped(static function (Container $c2) |
|
27 | + { |
|
26 | 28 | $obj = $c2->get(AttrScopeFooFinalize::class); |
27 | 29 | |
28 | 30 | self::assertFalse($obj->finalized); |
@@ -46,8 +48,10 @@ discard block |
||
46 | 48 | $root->bindSingleton(LoggerInterface::class, FileLogger::class); |
47 | 49 | |
48 | 50 | $obj2 = null; |
49 | - $obj = $root->runScoped(static function (Container $c1) use (&$obj2) { |
|
50 | - $obj = $c1->runScoped(static function (Container $c2) use (&$obj2) { |
|
51 | + $obj = $root->runScoped(static function (Container $c1) use (&$obj2) |
|
52 | + { |
|
53 | + $obj = $c1->runScoped(static function (Container $c2) use (&$obj2) |
|
54 | + { |
|
51 | 55 | $obj = $c2->get(AttrScopeFooFinalize::class); |
52 | 56 | $obj2 = $c2->get(AttrScopeFooFinalize::class); |
53 | 57 | |
@@ -77,8 +81,10 @@ discard block |
||
77 | 81 | $root->bindSingleton(LoggerInterface::class, FileLogger::class); |
78 | 82 | |
79 | 83 | $obj2 = null; |
80 | - $obj = $root->runScoped(static function (Container $c1) use (&$obj2) { |
|
81 | - $obj = $c1->runScoped(static function (Container $c2) use (&$obj2) { |
|
84 | + $obj = $root->runScoped(static function (Container $c1) use (&$obj2) |
|
85 | + { |
|
86 | + $obj = $c1->runScoped(static function (Container $c2) use (&$obj2) |
|
87 | + { |
|
82 | 88 | $obj = $c2->get(AttrFinalize::class); |
83 | 89 | $obj2 = $c2->get(AttrFinalize::class); |
84 | 90 | |
@@ -124,12 +130,15 @@ discard block |
||
124 | 130 | self::expectException(FinalizersException::class); |
125 | 131 | self::expectExceptionMessage('An exception has been thrown during finalization of the scope `foo`'); |
126 | 132 | |
127 | - try { |
|
133 | + try |
|
134 | + { |
|
128 | 135 | $root->runScoped(static function (Container $c1): void { |
129 | 136 | $obj = $c1->get(AttrScopeFooFinalize::class); |
130 | 137 | $obj->throwException = true; |
131 | 138 | }, name: 'foo'); |
132 | - } catch (FinalizersException $e) { |
|
139 | + } |
|
140 | + catch (FinalizersException $e) |
|
141 | + { |
|
133 | 142 | self::assertSame('foo', $e->getScope()); |
134 | 143 | self::assertCount(1, $e->getExceptions()); |
135 | 144 | // Contains the message from the inner exception. |
@@ -153,13 +162,16 @@ discard block |
||
153 | 162 | self::expectException(FinalizersException::class); |
154 | 163 | self::expectExceptionMessage('3 exceptions have been thrown during finalization of the scope `foo`'); |
155 | 164 | |
156 | - try { |
|
165 | + try |
|
166 | + { |
|
157 | 167 | $root->runScoped(static function (Container $c1): void { |
158 | 168 | $c1->get(AttrScopeFooFinalize::class)->throwException = true; |
159 | 169 | $c1->get(AttrScopeFooFinalize::class)->throwException = true; |
160 | 170 | $c1->get(AttrScopeFooFinalize::class)->throwException = true; |
161 | 171 | }, name: 'foo'); |
162 | - } catch (FinalizersException $e) { |
|
172 | + } |
|
173 | + catch (FinalizersException $e) |
|
174 | + { |
|
163 | 175 | self::assertSame('foo', $e->getScope()); |
164 | 176 | self::assertCount(3, $e->getExceptions()); |
165 | 177 | // Contains the message from the inner exception. |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | |
166 | 166 | $root = self::makeContainer(); |
167 | 167 | |
168 | - try { |
|
168 | + try{ |
|
169 | 169 | $root->runScoped(static function (Container $c1): void { |
170 | 170 | $c1->runScoped(static function (Container $c2): void { |
171 | 171 | $c2->runScoped(static function (Container $c3): void { |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | }, name: 'root'); |
174 | 174 | }); |
175 | 175 | }); |
176 | - } catch (NamedScopeDuplicationException $e) { |
|
176 | + }catch (NamedScopeDuplicationException $e){ |
|
177 | 177 | self::assertSame('root', $e->getScope()); |
178 | 178 | throw $e; |
179 | 179 | } |
@@ -188,14 +188,14 @@ discard block |
||
188 | 188 | { |
189 | 189 | self::expectException(BadScopeException::class); |
190 | 190 | |
191 | - try { |
|
191 | + try{ |
|
192 | 192 | $root = self::makeContainer(); |
193 | 193 | $root->runScoped(static function (Container $c1): void { |
194 | 194 | $c1->runScoped(static function (Container $c2): void { |
195 | 195 | $c2->get(AttrScopeFoo::class); |
196 | 196 | }); |
197 | 197 | }, name: 'bar'); |
198 | - } catch (BadScopeException $e) { |
|
198 | + }catch (BadScopeException $e){ |
|
199 | 199 | self::assertSame('foo', $e->getScope()); |
200 | 200 | throw $e; |
201 | 201 | } |
@@ -165,7 +165,8 @@ discard block |
||
165 | 165 | |
166 | 166 | $root = self::makeContainer(); |
167 | 167 | |
168 | - try { |
|
168 | + try |
|
169 | + { |
|
169 | 170 | $root->runScoped(static function (Container $c1): void { |
170 | 171 | $c1->runScoped(static function (Container $c2): void { |
171 | 172 | $c2->runScoped(static function (Container $c3): void { |
@@ -173,7 +174,9 @@ discard block |
||
173 | 174 | }, name: 'root'); |
174 | 175 | }); |
175 | 176 | }); |
176 | - } catch (NamedScopeDuplicationException $e) { |
|
177 | + } |
|
178 | + catch (NamedScopeDuplicationException $e) |
|
179 | + { |
|
177 | 180 | self::assertSame('root', $e->getScope()); |
178 | 181 | throw $e; |
179 | 182 | } |
@@ -188,14 +191,17 @@ discard block |
||
188 | 191 | { |
189 | 192 | self::expectException(BadScopeException::class); |
190 | 193 | |
191 | - try { |
|
194 | + try |
|
195 | + { |
|
192 | 196 | $root = self::makeContainer(); |
193 | 197 | $root->runScoped(static function (Container $c1): void { |
194 | 198 | $c1->runScoped(static function (Container $c2): void { |
195 | 199 | $c2->get(AttrScopeFoo::class); |
196 | 200 | }); |
197 | 201 | }, name: 'bar'); |
198 | - } catch (BadScopeException $e) { |
|
202 | + } |
|
203 | + catch (BadScopeException $e) |
|
204 | + { |
|
199 | 205 | self::assertSame('foo', $e->getScope()); |
200 | 206 | throw $e; |
201 | 207 | } |
@@ -21,10 +21,10 @@ discard block |
||
21 | 21 | $container = new Container(); |
22 | 22 | |
23 | 23 | $container->runScoped(static function (Container $c1): void { |
24 | - try { |
|
24 | + try{ |
|
25 | 25 | $c1->get(ExceptionConstructor::class); |
26 | 26 | self::fail('Exception should be thrown'); |
27 | - } catch (\Throwable $e) { |
|
27 | + }catch (\Throwable $e){ |
|
28 | 28 | self::assertInstanceOf(\Exception::class, $e); |
29 | 29 | throw $e; |
30 | 30 | } |
@@ -39,10 +39,10 @@ discard block |
||
39 | 39 | $container = new Container(); |
40 | 40 | |
41 | 41 | $container->runScoped(static function (Container $c1): void { |
42 | - try { |
|
42 | + try{ |
|
43 | 43 | $c1->get(ExceptionConstructor::class); |
44 | 44 | self::fail('Exception should be thrown'); |
45 | - } catch (\Throwable $e) { |
|
45 | + }catch (\Throwable $e){ |
|
46 | 46 | self::assertInstanceOf(\Exception::class, $e); |
47 | 47 | throw $e; |
48 | 48 | } |
@@ -57,10 +57,10 @@ discard block |
||
57 | 57 | $container = new Container(); |
58 | 58 | |
59 | 59 | $container->runScoped(static function (Container $c1): void { |
60 | - try { |
|
60 | + try{ |
|
61 | 61 | $c1->get(DatetimeCarrier::class); |
62 | 62 | self::fail('Exception should be thrown'); |
63 | - } catch (\Throwable $e) { |
|
63 | + }catch (\Throwable $e){ |
|
64 | 64 | self::assertInstanceOf(NotFoundException::class, $e); |
65 | 65 | self::assertInstanceOf(NotFoundException::class, $e->getPrevious()); |
66 | 66 | self::assertStringContainsString( |
@@ -21,10 +21,13 @@ discard block |
||
21 | 21 | $container = new Container(); |
22 | 22 | |
23 | 23 | $container->runScoped(static function (Container $c1): void { |
24 | - try { |
|
24 | + try |
|
25 | + { |
|
25 | 26 | $c1->get(ExceptionConstructor::class); |
26 | 27 | self::fail('Exception should be thrown'); |
27 | - } catch (\Throwable $e) { |
|
28 | + } |
|
29 | + catch (\Throwable $e) |
|
30 | + { |
|
28 | 31 | self::assertInstanceOf(\Exception::class, $e); |
29 | 32 | throw $e; |
30 | 33 | } |
@@ -39,10 +42,13 @@ discard block |
||
39 | 42 | $container = new Container(); |
40 | 43 | |
41 | 44 | $container->runScoped(static function (Container $c1): void { |
42 | - try { |
|
45 | + try |
|
46 | + { |
|
43 | 47 | $c1->get(ExceptionConstructor::class); |
44 | 48 | self::fail('Exception should be thrown'); |
45 | - } catch (\Throwable $e) { |
|
49 | + } |
|
50 | + catch (\Throwable $e) |
|
51 | + { |
|
46 | 52 | self::assertInstanceOf(\Exception::class, $e); |
47 | 53 | throw $e; |
48 | 54 | } |
@@ -57,10 +63,13 @@ discard block |
||
57 | 63 | $container = new Container(); |
58 | 64 | |
59 | 65 | $container->runScoped(static function (Container $c1): void { |
60 | - try { |
|
66 | + try |
|
67 | + { |
|
61 | 68 | $c1->get(DatetimeCarrier::class); |
62 | 69 | self::fail('Exception should be thrown'); |
63 | - } catch (\Throwable $e) { |
|
70 | + } |
|
71 | + catch (\Throwable $e) |
|
72 | + { |
|
64 | 73 | self::assertInstanceOf(NotFoundException::class, $e); |
65 | 74 | self::assertInstanceOf(NotFoundException::class, $e->getPrevious()); |
66 | 75 | self::assertStringContainsString( |
@@ -60,7 +60,8 @@ discard block |
||
60 | 60 | |
61 | 61 | public function testMiddlewareProcessingEventShouldBeDispatched(): void |
62 | 62 | { |
63 | - $middleware = new class implements MiddlewareInterface { |
|
63 | + $middleware = new class implements MiddlewareInterface |
|
64 | + { |
|
64 | 65 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
65 | 66 | { |
66 | 67 | return (new ResponseFactory(new HttpConfig(['headers' => []])))->createResponse(200); |
@@ -89,7 +90,8 @@ discard block |
||
89 | 90 | $this->container->getBinder('http') |
90 | 91 | ->bind(ServerRequestInterface::class, static fn(CurrentRequest $cr): ?ServerRequestInterface => $cr->get()); |
91 | 92 | |
92 | - $middleware = new class implements MiddlewareInterface { |
|
93 | + $middleware = new class implements MiddlewareInterface |
|
94 | + { |
|
93 | 95 | public function process( |
94 | 96 | ServerRequestInterface $request, |
95 | 97 | RequestHandlerInterface $handler, |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | |
34 | 34 | self::assertSame(200, $response->getStatusCode()); |
35 | 35 | self::assertSame('OK', $response->getReasonPhrase()); |
36 | - self::assertSame('response', (string) $response->getBody()); |
|
36 | + self::assertSame('response', (string)$response->getBody()); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | public function testHandle(): void |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | |
47 | 47 | self::assertSame(200, $response->getStatusCode()); |
48 | 48 | self::assertSame('OK', $response->getReasonPhrase()); |
49 | - self::assertSame('response', (string) $response->getBody()); |
|
49 | + self::assertSame('response', (string)$response->getBody()); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | public function testHandleException(): void |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | |
60 | 60 | public function testMiddlewareProcessingEventShouldBeDispatched(): void |
61 | 61 | { |
62 | - $middleware = new class implements MiddlewareInterface { |
|
62 | + $middleware = new class implements MiddlewareInterface{ |
|
63 | 63 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
64 | 64 | { |
65 | 65 | return (new ResponseFactory(new HttpConfig(['headers' => []])))->createResponse(200); |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | $this->container->getBinder('http') |
89 | 89 | ->bind(ServerRequestInterface::class, static fn(CurrentRequest $cr): ?ServerRequestInterface => $cr->get()); |
90 | 90 | |
91 | - $middleware = new class implements MiddlewareInterface { |
|
91 | + $middleware = new class implements MiddlewareInterface{ |
|
92 | 92 | public function process( |
93 | 93 | ServerRequestInterface $request, |
94 | 94 | RequestHandlerInterface $handler, |
@@ -48,7 +48,7 @@ |
||
48 | 48 | static function (DistributionConfig $config): DistributionInterface { |
49 | 49 | $manager = new Manager($config->getDefaultDriver()); |
50 | 50 | |
51 | - foreach ($config->getResolvers() as $name => $resolver) { |
|
51 | + foreach ($config->getResolvers() as $name => $resolver){ |
|
52 | 52 | $manager->add($name, $resolver); |
53 | 53 | } |
54 | 54 |
@@ -48,7 +48,8 @@ |
||
48 | 48 | static function (DistributionConfig $config): DistributionInterface { |
49 | 49 | $manager = new Manager($config->getDefaultDriver()); |
50 | 50 | |
51 | - foreach ($config->getResolvers() as $name => $resolver) { |
|
51 | + foreach ($config->getResolvers() as $name => $resolver) |
|
52 | + { |
|
52 | 53 | $manager->add($name, $resolver); |
53 | 54 | } |
54 | 55 |
@@ -68,13 +68,17 @@ discard block |
||
68 | 68 | return $this->tracer->trace( |
69 | 69 | name: 'Routing', |
70 | 70 | callback: function (SpanInterface $span) use ($request): ResponseInterface { |
71 | - try { |
|
71 | + try |
|
72 | + { |
|
72 | 73 | $route = $this->matchRoute($request, $routeName); |
73 | - } catch (RouteException $e) { |
|
74 | + } |
|
75 | + catch (RouteException $e) |
|
76 | + { |
|
74 | 77 | throw new RouterException('Invalid route definition', $e->getCode(), $e); |
75 | 78 | } |
76 | 79 | |
77 | - if ($route === null) { |
|
80 | + if ($route === null) |
|
81 | + { |
|
78 | 82 | $this->eventDispatcher?->dispatch(new RouteNotFound($request)); |
79 | 83 | throw new RouteNotFoundException($request->getUri()); |
80 | 84 | } |
@@ -109,7 +113,8 @@ discard block |
||
109 | 113 | |
110 | 114 | public function getRoute(string $name): RouteInterface |
111 | 115 | { |
112 | - if (isset($this->routes[$name])) { |
|
116 | + if (isset($this->routes[$name])) |
|
117 | + { |
|
113 | 118 | return $this->routes[$name]; |
114 | 119 | } |
115 | 120 | |
@@ -118,7 +123,8 @@ discard block |
||
118 | 123 | |
119 | 124 | public function getRoutes(): array |
120 | 125 | { |
121 | - if (!empty($this->default)) { |
|
126 | + if (!empty($this->default)) |
|
127 | + { |
|
122 | 128 | return $this->routes + [null => $this->default]; |
123 | 129 | } |
124 | 130 | |
@@ -127,9 +133,12 @@ discard block |
||
127 | 133 | |
128 | 134 | public function uri(string $route, iterable $parameters = []): UriInterface |
129 | 135 | { |
130 | - try { |
|
136 | + try |
|
137 | + { |
|
131 | 138 | return $this->getRoute($route)->uri($parameters); |
132 | - } catch (UndefinedRouteException) { |
|
139 | + } |
|
140 | + catch (UndefinedRouteException) |
|
141 | + { |
|
133 | 142 | //In some cases route name can be provided as controller:action pair, we can try to |
134 | 143 | //generate such route automatically based on our default/fallback route |
135 | 144 | return $this->castRoute($route)->uri($parameters); |
@@ -141,9 +150,11 @@ discard block |
||
141 | 150 | /** @var GroupRegistry $groups */ |
142 | 151 | $groups = $this->container->get(GroupRegistry::class); |
143 | 152 | |
144 | - foreach ($routes->getCollection() as $name => $configurator) { |
|
153 | + foreach ($routes->getCollection() as $name => $configurator) |
|
154 | + { |
|
145 | 155 | $target = $configurator->target; |
146 | - if ($configurator->core !== null && $target instanceof AbstractTarget) { |
|
156 | + if ($configurator->core !== null && $target instanceof AbstractTarget) |
|
157 | + { |
|
147 | 158 | $target = $target->withCore($configurator->core); |
148 | 159 | } |
149 | 160 | |
@@ -152,21 +163,25 @@ discard block |
||
152 | 163 | : \ltrim($configurator->pattern, '/'); |
153 | 164 | $route = new Route($pattern, $target, $configurator->defaults); |
154 | 165 | |
155 | - if ($configurator->middleware !== null) { |
|
166 | + if ($configurator->middleware !== null) |
|
167 | + { |
|
156 | 168 | $route = $route->withMiddleware(...$configurator->middleware); |
157 | 169 | } |
158 | 170 | |
159 | - if ($configurator->methods !== null) { |
|
171 | + if ($configurator->methods !== null) |
|
172 | + { |
|
160 | 173 | $route = $route->withVerbs(...$configurator->methods); |
161 | 174 | } |
162 | 175 | |
163 | - if (!isset($this->routes[$name]) && $name !== RoutingConfigurator::DEFAULT_ROUTE_NAME) { |
|
176 | + if (!isset($this->routes[$name]) && $name !== RoutingConfigurator::DEFAULT_ROUTE_NAME) |
|
177 | + { |
|
164 | 178 | $group = $groups->getGroup($configurator->group ?? $groups->getDefaultGroup()); |
165 | 179 | $group->setPrefix($configurator->prefix); |
166 | 180 | $group->addRoute($name, $route); |
167 | 181 | } |
168 | 182 | |
169 | - if ($name === RoutingConfigurator::DEFAULT_ROUTE_NAME) { |
|
183 | + if ($name === RoutingConfigurator::DEFAULT_ROUTE_NAME) |
|
184 | + { |
|
170 | 185 | $this->setDefault($route); |
171 | 186 | } |
172 | 187 | } |
@@ -177,17 +192,20 @@ discard block |
||
177 | 192 | */ |
178 | 193 | protected function matchRoute(ServerRequestInterface $request, ?string &$routeName = null): ?RouteInterface |
179 | 194 | { |
180 | - foreach ($this->routes as $name => $route) { |
|
195 | + foreach ($this->routes as $name => $route) |
|
196 | + { |
|
181 | 197 | // Matched route will return new route instance with matched parameters |
182 | 198 | $matched = $route->match($request); |
183 | 199 | |
184 | - if ($matched !== null) { |
|
200 | + if ($matched !== null) |
|
201 | + { |
|
185 | 202 | $routeName = $name; |
186 | 203 | return $matched; |
187 | 204 | } |
188 | 205 | } |
189 | 206 | |
190 | - if ($this->default !== null) { |
|
207 | + if ($this->default !== null) |
|
208 | + { |
|
191 | 209 | return $this->default->match($request); |
192 | 210 | } |
193 | 211 | |
@@ -200,14 +218,18 @@ discard block |
||
200 | 218 | */ |
201 | 219 | protected function configure(RouteInterface $route): RouteInterface |
202 | 220 | { |
203 | - if ($route instanceof ContainerizedInterface && !$route->hasContainer()) { |
|
221 | + if ($route instanceof ContainerizedInterface && !$route->hasContainer()) |
|
222 | + { |
|
204 | 223 | // isolating route in a given container |
205 | 224 | $route = $route->withContainer($this->container); |
206 | 225 | } |
207 | 226 | |
208 | - try { |
|
227 | + try |
|
228 | + { |
|
209 | 229 | $uriHandler = $route->getUriHandler(); |
210 | - } catch (\Throwable) { |
|
230 | + } |
|
231 | + catch (\Throwable) |
|
232 | + { |
|
211 | 233 | $uriHandler = $this->uriHandler; |
212 | 234 | } |
213 | 235 | |
@@ -239,11 +261,16 @@ discard block |
||
239 | 261 | /** |
240 | 262 | * @var Matches $matches |
241 | 263 | */ |
242 | - if (!empty($matches['name'])) { |
|
264 | + if (!empty($matches['name'])) |
|
265 | + { |
|
243 | 266 | $routeObject = $this->getRoute($matches['name']); |
244 | - } elseif ($this->default !== null) { |
|
267 | + } |
|
268 | + elseif ($this->default !== null) |
|
269 | + { |
|
245 | 270 | $routeObject = $this->default; |
246 | - } else { |
|
271 | + } |
|
272 | + else |
|
273 | + { |
|
247 | 274 | throw new UndefinedRouteException(\sprintf('Unable to locate route candidate for `%s`', $route)); |
248 | 275 | } |
249 | 276 |
@@ -52,9 +52,9 @@ discard block |
||
52 | 52 | private readonly ContainerInterface $container, |
53 | 53 | private readonly ?EventDispatcherInterface $eventDispatcher = null, |
54 | 54 | ?TracerInterface $tracer = null, |
55 | - ) { |
|
55 | + ){ |
|
56 | 56 | $this->tracer = $tracer ?? new NullTracer(); |
57 | - $this->basePath = '/' . \ltrim($basePath, '/'); |
|
57 | + $this->basePath = '/'.\ltrim($basePath, '/'); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -68,19 +68,19 @@ discard block |
||
68 | 68 | return $this->tracer->trace( |
69 | 69 | name: 'Routing', |
70 | 70 | callback: function (SpanInterface $span) use ($request): ResponseInterface { |
71 | - try { |
|
71 | + try{ |
|
72 | 72 | $route = $this->matchRoute($request, $routeName); |
73 | - } catch (RouteException $e) { |
|
73 | + }catch (RouteException $e){ |
|
74 | 74 | throw new RouterException('Invalid route definition', $e->getCode(), $e); |
75 | 75 | } |
76 | 76 | |
77 | - if ($route === null) { |
|
77 | + if ($route === null){ |
|
78 | 78 | $this->eventDispatcher?->dispatch(new RouteNotFound($request)); |
79 | 79 | throw new RouteNotFoundException($request->getUri()); |
80 | 80 | } |
81 | 81 | |
82 | 82 | $span |
83 | - ->setAttribute('request.uri', (string) $request->getUri()) |
|
83 | + ->setAttribute('request.uri', (string)$request->getUri()) |
|
84 | 84 | ->setAttribute('route.name', $routeName) |
85 | 85 | ->setAttribute('route.matches', $route->getMatches() ?? []); |
86 | 86 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | |
110 | 110 | public function getRoute(string $name): RouteInterface |
111 | 111 | { |
112 | - if (isset($this->routes[$name])) { |
|
112 | + if (isset($this->routes[$name])){ |
|
113 | 113 | return $this->routes[$name]; |
114 | 114 | } |
115 | 115 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | |
119 | 119 | public function getRoutes(): array |
120 | 120 | { |
121 | - if (!empty($this->default)) { |
|
121 | + if (!empty($this->default)){ |
|
122 | 122 | return $this->routes + [null => $this->default]; |
123 | 123 | } |
124 | 124 | |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | |
128 | 128 | public function uri(string $route, iterable $parameters = []): UriInterface |
129 | 129 | { |
130 | - try { |
|
130 | + try{ |
|
131 | 131 | return $this->getRoute($route)->uri($parameters); |
132 | - } catch (UndefinedRouteException) { |
|
132 | + }catch (UndefinedRouteException){ |
|
133 | 133 | //In some cases route name can be provided as controller:action pair, we can try to |
134 | 134 | //generate such route automatically based on our default/fallback route |
135 | 135 | return $this->castRoute($route)->uri($parameters); |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | /** @var GroupRegistry $groups */ |
142 | 142 | $groups = $this->container->get(GroupRegistry::class); |
143 | 143 | |
144 | - foreach ($routes->getCollection() as $name => $configurator) { |
|
144 | + foreach ($routes->getCollection() as $name => $configurator){ |
|
145 | 145 | $target = $configurator->target; |
146 | - if ($configurator->core !== null && $target instanceof AbstractTarget) { |
|
146 | + if ($configurator->core !== null && $target instanceof AbstractTarget){ |
|
147 | 147 | $target = $target->withCore($configurator->core); |
148 | 148 | } |
149 | 149 | |
@@ -152,21 +152,21 @@ discard block |
||
152 | 152 | : \ltrim($configurator->pattern, '/'); |
153 | 153 | $route = new Route($pattern, $target, $configurator->defaults); |
154 | 154 | |
155 | - if ($configurator->middleware !== null) { |
|
155 | + if ($configurator->middleware !== null){ |
|
156 | 156 | $route = $route->withMiddleware(...$configurator->middleware); |
157 | 157 | } |
158 | 158 | |
159 | - if ($configurator->methods !== null) { |
|
159 | + if ($configurator->methods !== null){ |
|
160 | 160 | $route = $route->withVerbs(...$configurator->methods); |
161 | 161 | } |
162 | 162 | |
163 | - if (!isset($this->routes[$name]) && $name !== RoutingConfigurator::DEFAULT_ROUTE_NAME) { |
|
163 | + if (!isset($this->routes[$name]) && $name !== RoutingConfigurator::DEFAULT_ROUTE_NAME){ |
|
164 | 164 | $group = $groups->getGroup($configurator->group ?? $groups->getDefaultGroup()); |
165 | 165 | $group->setPrefix($configurator->prefix); |
166 | 166 | $group->addRoute($name, $route); |
167 | 167 | } |
168 | 168 | |
169 | - if ($name === RoutingConfigurator::DEFAULT_ROUTE_NAME) { |
|
169 | + if ($name === RoutingConfigurator::DEFAULT_ROUTE_NAME){ |
|
170 | 170 | $this->setDefault($route); |
171 | 171 | } |
172 | 172 | } |
@@ -177,17 +177,17 @@ discard block |
||
177 | 177 | */ |
178 | 178 | protected function matchRoute(ServerRequestInterface $request, ?string &$routeName = null): ?RouteInterface |
179 | 179 | { |
180 | - foreach ($this->routes as $name => $route) { |
|
180 | + foreach ($this->routes as $name => $route){ |
|
181 | 181 | // Matched route will return new route instance with matched parameters |
182 | 182 | $matched = $route->match($request); |
183 | 183 | |
184 | - if ($matched !== null) { |
|
184 | + if ($matched !== null){ |
|
185 | 185 | $routeName = $name; |
186 | 186 | return $matched; |
187 | 187 | } |
188 | 188 | } |
189 | 189 | |
190 | - if ($this->default !== null) { |
|
190 | + if ($this->default !== null){ |
|
191 | 191 | return $this->default->match($request); |
192 | 192 | } |
193 | 193 | |
@@ -200,14 +200,14 @@ discard block |
||
200 | 200 | */ |
201 | 201 | protected function configure(RouteInterface $route): RouteInterface |
202 | 202 | { |
203 | - if ($route instanceof ContainerizedInterface && !$route->hasContainer()) { |
|
203 | + if ($route instanceof ContainerizedInterface && !$route->hasContainer()){ |
|
204 | 204 | // isolating route in a given container |
205 | 205 | $route = $route->withContainer($this->container); |
206 | 206 | } |
207 | 207 | |
208 | - try { |
|
208 | + try{ |
|
209 | 209 | $uriHandler = $route->getUriHandler(); |
210 | - } catch (\Throwable) { |
|
210 | + }catch (\Throwable){ |
|
211 | 211 | $uriHandler = $this->uriHandler; |
212 | 212 | } |
213 | 213 | |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | $route, |
231 | 231 | $matches, |
232 | 232 | ) |
233 | - ) { |
|
233 | + ){ |
|
234 | 234 | throw new UndefinedRouteException( |
235 | 235 | "Unable to locate route or use default route with 'name/controller:action' pattern", |
236 | 236 | ); |
@@ -239,11 +239,11 @@ discard block |
||
239 | 239 | /** |
240 | 240 | * @var Matches $matches |
241 | 241 | */ |
242 | - if (!empty($matches['name'])) { |
|
242 | + if (!empty($matches['name'])){ |
|
243 | 243 | $routeObject = $this->getRoute($matches['name']); |
244 | - } elseif ($this->default !== null) { |
|
244 | + } elseif ($this->default !== null){ |
|
245 | 245 | $routeObject = $this->default; |
246 | - } else { |
|
246 | + }else{ |
|
247 | 247 | throw new UndefinedRouteException(\sprintf('Unable to locate route candidate for `%s`', $route)); |
248 | 248 | } |
249 | 249 |
@@ -135,9 +135,9 @@ discard block |
||
135 | 135 | { |
136 | 136 | $container = new Container(); |
137 | 137 | |
138 | - try { |
|
138 | + try{ |
|
139 | 139 | $container->get('invalid'); |
140 | - } catch (ContainerException $e) { |
|
140 | + }catch (ContainerException $e){ |
|
141 | 141 | self::assertSame(<<<MARKDOWN |
142 | 142 | Can't resolve `invalid`: undefined class or binding `invalid`. |
143 | 143 | Container trace list: |
@@ -166,9 +166,9 @@ discard block |
||
166 | 166 | { |
167 | 167 | $this->expectException(ContainerException::class); |
168 | 168 | |
169 | - try { |
|
169 | + try{ |
|
170 | 170 | $container->get(ClassWithUndefinedDependency::class); |
171 | - } catch (ContainerException $e) { |
|
171 | + }catch (ContainerException $e){ |
|
172 | 172 | self::assertSame($message, $e->getMessage()); |
173 | 173 | |
174 | 174 | throw $e; |
@@ -135,9 +135,12 @@ discard block |
||
135 | 135 | { |
136 | 136 | $container = new Container(); |
137 | 137 | |
138 | - try { |
|
138 | + try |
|
139 | + { |
|
139 | 140 | $container->get('invalid'); |
140 | - } catch (ContainerException $e) { |
|
141 | + } |
|
142 | + catch (ContainerException $e) |
|
143 | + { |
|
141 | 144 | self::assertSame(<<<MARKDOWN |
142 | 145 | Can't resolve `invalid`: undefined class or binding `invalid`. |
143 | 146 | Container trace list: |
@@ -166,9 +169,12 @@ discard block |
||
166 | 169 | { |
167 | 170 | $this->expectException(ContainerException::class); |
168 | 171 | |
169 | - try { |
|
172 | + try |
|
173 | + { |
|
170 | 174 | $container->get(ClassWithUndefinedDependency::class); |
171 | - } catch (ContainerException $e) { |
|
175 | + } |
|
176 | + catch (ContainerException $e) |
|
177 | + { |
|
172 | 178 | self::assertSame($message, $e->getMessage()); |
173 | 179 | |
174 | 180 | throw $e; |