@@ -11,7 +11,7 @@ |
||
11 | 11 | { |
12 | 12 | public function __construct( |
13 | 13 | private readonly ?ScopeInterface $scope = new Container(), |
14 | - ) { |
|
14 | + ){ |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | public function make(array $context = []): TracerInterface |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | { |
20 | 20 | public function init(HttpBootloader $http): void |
21 | 21 | { |
22 | - foreach ($this->globalMiddleware() as $middleware) { |
|
22 | + foreach ($this->globalMiddleware() as $middleware){ |
|
23 | 23 | $http->addMiddleware($middleware); |
24 | 24 | } |
25 | 25 | } |
@@ -61,11 +61,11 @@ discard block |
||
61 | 61 | |
62 | 62 | private function registerMiddlewareGroups(BinderInterface $binder, array $groups): void |
63 | 63 | { |
64 | - foreach ($groups as $group => $middleware) { |
|
64 | + foreach ($groups as $group => $middleware){ |
|
65 | 65 | $binder |
66 | 66 | ->getBinder('http') |
67 | 67 | ->bind( |
68 | - 'middleware:' . $group, |
|
68 | + 'middleware:'.$group, |
|
69 | 69 | static function (FactoryInterface $factory) use ($middleware): LazyPipeline { |
70 | 70 | return $factory->make(LazyPipeline::class)->withAddedMiddleware(...$middleware); |
71 | 71 | } |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | |
76 | 76 | private function registerMiddlewareForRouteGroups(GroupRegistry $registry, array $groups): void |
77 | 77 | { |
78 | - foreach ($groups as $group) { |
|
79 | - $registry->getGroup($group)->addMiddleware('middleware:' . $group); |
|
78 | + foreach ($groups as $group){ |
|
79 | + $registry->getGroup($group)->addMiddleware('middleware:'.$group); |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | } |
@@ -19,7 +19,8 @@ discard block |
||
19 | 19 | { |
20 | 20 | public function init(HttpBootloader $http): void |
21 | 21 | { |
22 | - foreach ($this->globalMiddleware() as $middleware) { |
|
22 | + foreach ($this->globalMiddleware() as $middleware) |
|
23 | + { |
|
23 | 24 | $http->addMiddleware($middleware); |
24 | 25 | } |
25 | 26 | } |
@@ -61,7 +62,8 @@ discard block |
||
61 | 62 | |
62 | 63 | private function registerMiddlewareGroups(BinderInterface $binder, array $groups): void |
63 | 64 | { |
64 | - foreach ($groups as $group => $middleware) { |
|
65 | + foreach ($groups as $group => $middleware) |
|
66 | + { |
|
65 | 67 | $binder |
66 | 68 | ->getBinder('http') |
67 | 69 | ->bind( |
@@ -75,7 +77,8 @@ discard block |
||
75 | 77 | |
76 | 78 | private function registerMiddlewareForRouteGroups(GroupRegistry $registry, array $groups): void |
77 | 79 | { |
78 | - foreach ($groups as $group) { |
|
80 | + foreach ($groups as $group) |
|
81 | + { |
|
79 | 82 | $registry->getGroup($group)->addMiddleware('middleware:' . $group); |
80 | 83 | } |
81 | 84 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | public function __construct( |
40 | 40 | #[Proxy] private readonly ContainerInterface $container, |
41 | 41 | private readonly ?EventDispatcherInterface $dispatcher = null, |
42 | - ) { |
|
42 | + ){ |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @param MiddlewareInterface ...$middleware List of middleware or its definition. |
49 | 49 | */ |
50 | - public function withAddedMiddleware(MiddlewareInterface|Autowire|string ...$middleware): self |
|
50 | + public function withAddedMiddleware(MiddlewareInterface | Autowire | string ...$middleware): self |
|
51 | 51 | { |
52 | 52 | $pipeline = clone $this; |
53 | 53 | $pipeline->middleware = \array_merge($pipeline->middleware, $middleware); |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @param MiddlewareInterface ...$middleware List of middleware or its definition. |
61 | 61 | */ |
62 | - public function withMiddleware(MiddlewareInterface|Autowire|string ...$middleware): self |
|
62 | + public function withMiddleware(MiddlewareInterface | Autowire | string ...$middleware): self |
|
63 | 63 | { |
64 | 64 | $pipeline = clone $this; |
65 | 65 | $pipeline->middleware = $middleware; |
@@ -92,9 +92,9 @@ discard block |
||
92 | 92 | |
93 | 93 | $previousRequest = $currentRequest->get(); |
94 | 94 | $currentRequest->set($request); |
95 | - try { |
|
95 | + try{ |
|
96 | 96 | // There is no middleware to process, let's pass the request to the handler |
97 | - if (!\array_key_exists($this->position, $this->middleware)) { |
|
97 | + if (!\array_key_exists($this->position, $this->middleware)){ |
|
98 | 98 | return $this->handler->handle($request); |
99 | 99 | } |
100 | 100 | |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | ? \sprintf('%s=%s', $this->middleware[$this->position], $middleware::class) |
109 | 109 | : $middleware::class; |
110 | 110 | // Init a tracing span when the pipeline starts |
111 | - if ($span === null) { |
|
111 | + if ($span === null){ |
|
112 | 112 | /** @var TracerInterface $tracer */ |
113 | 113 | $tracer = $this->container->get(TracerInterface::class); |
114 | 114 | return $tracer->trace( |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $span->setAttribute('http.middleware', $middlewares); |
127 | 127 | |
128 | 128 | return $middleware->process($request, $this->next($span)); |
129 | - } finally { |
|
129 | + }finally{ |
|
130 | 130 | $currentRequest->set($previousRequest); |
131 | 131 | } |
132 | 132 | } |
@@ -92,9 +92,11 @@ discard block |
||
92 | 92 | |
93 | 93 | $previousRequest = $currentRequest->get(); |
94 | 94 | $currentRequest->set($request); |
95 | - try { |
|
95 | + try |
|
96 | + { |
|
96 | 97 | // There is no middleware to process, let's pass the request to the handler |
97 | - if (!\array_key_exists($this->position, $this->middleware)) { |
|
98 | + if (!\array_key_exists($this->position, $this->middleware)) |
|
99 | + { |
|
98 | 100 | return $this->handler->handle($request); |
99 | 101 | } |
100 | 102 | |
@@ -108,7 +110,8 @@ discard block |
||
108 | 110 | ? \sprintf('%s=%s', $this->middleware[$this->position], $middleware::class) |
109 | 111 | : $middleware::class; |
110 | 112 | // Init a tracing span when the pipeline starts |
111 | - if ($span === null) { |
|
113 | + if ($span === null) |
|
114 | + { |
|
112 | 115 | /** @var TracerInterface $tracer */ |
113 | 116 | $tracer = $this->container->get(TracerInterface::class); |
114 | 117 | return $tracer->trace( |
@@ -126,7 +129,9 @@ discard block |
||
126 | 129 | $span->setAttribute('http.middleware', $middlewares); |
127 | 130 | |
128 | 131 | return $middleware->process($request, $this->next($span)); |
129 | - } finally { |
|
132 | + } |
|
133 | + finally |
|
134 | + { |
|
130 | 135 | $currentRequest->set($previousRequest); |
131 | 136 | } |
132 | 137 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | #[Proxy] ScopeInterface $scope, |
36 | 36 | private readonly ?EventDispatcherInterface $dispatcher = null, |
37 | 37 | ?TracerInterface $tracer = null |
38 | - ) { |
|
38 | + ){ |
|
39 | 39 | $this->tracer = $tracer ?? new NullTracer($scope); |
40 | 40 | } |
41 | 41 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | |
61 | 61 | public function handle(Request $request): Response |
62 | 62 | { |
63 | - if ($this->handler === null) { |
|
63 | + if ($this->handler === null){ |
|
64 | 64 | throw new PipelineException('Unable to run pipeline, no handler given.'); |
65 | 65 | } |
66 | 66 | |
@@ -70,9 +70,9 @@ discard block |
||
70 | 70 | |
71 | 71 | $previousRequest = $currentRequest?->get(); |
72 | 72 | $currentRequest?->set($request); |
73 | - try { |
|
73 | + try{ |
|
74 | 74 | $position = $this->position++; |
75 | - if (!isset($this->middleware[$position])) { |
|
75 | + if (!isset($this->middleware[$position])){ |
|
76 | 76 | return $this->handler->handle($request); |
77 | 77 | } |
78 | 78 | |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | ], |
105 | 105 | scoped: true |
106 | 106 | ); |
107 | - } finally { |
|
108 | - if ($previousRequest !== null) { |
|
107 | + }finally{ |
|
108 | + if ($previousRequest !== null){ |
|
109 | 109 | $currentRequest?->set($previousRequest); |
110 | 110 | } |
111 | 111 | } |
@@ -25,21 +25,21 @@ discard block |
||
25 | 25 | { |
26 | 26 | private ?RequestHandlerInterface $handler = null; |
27 | 27 | private readonly TracerFactoryInterface $tracerFactory; |
28 | - private readonly Pipeline|LazyPipeline $pipeline; |
|
28 | + private readonly Pipeline | LazyPipeline $pipeline; |
|
29 | 29 | |
30 | 30 | public function __construct( |
31 | 31 | private readonly HttpConfig $config, |
32 | - Pipeline|LazyPipeline $pipeline, |
|
32 | + Pipeline | LazyPipeline $pipeline, |
|
33 | 33 | private readonly ResponseFactoryInterface $responseFactory, |
34 | 34 | private readonly ContainerInterface $container, |
35 | 35 | ?TracerFactoryInterface $tracerFactory = null, |
36 | 36 | private readonly ?EventDispatcherInterface $dispatcher = null, |
37 | - ) { |
|
38 | - if ($pipeline instanceof Pipeline) { |
|
39 | - foreach ($this->config->getMiddleware() as $middleware) { |
|
37 | + ){ |
|
38 | + if ($pipeline instanceof Pipeline){ |
|
39 | + foreach ($this->config->getMiddleware() as $middleware){ |
|
40 | 40 | $pipeline->pushMiddleware($this->container->get($middleware)); |
41 | 41 | } |
42 | - } else { |
|
42 | + }else{ |
|
43 | 43 | $pipeline = $pipeline->withAddedMiddleware( |
44 | 44 | ...$this->config->getMiddleware() |
45 | 45 | ); |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | /** |
54 | 54 | * @internal |
55 | 55 | */ |
56 | - public function getPipeline(): Pipeline|LazyPipeline |
|
56 | + public function getPipeline(): Pipeline | LazyPipeline |
|
57 | 57 | { |
58 | 58 | return $this->pipeline; |
59 | 59 | } |
60 | 60 | |
61 | - public function setHandler(callable|RequestHandlerInterface $handler): self |
|
61 | + public function setHandler(callable | RequestHandlerInterface $handler): self |
|
62 | 62 | { |
63 | 63 | $this->handler = $handler instanceof RequestHandlerInterface |
64 | 64 | ? $handler |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | |
78 | 78 | $this->dispatcher?->dispatch(new RequestReceived($request)); |
79 | 79 | |
80 | - if ($this->handler === null) { |
|
80 | + if ($this->handler === null){ |
|
81 | 81 | throw new HttpException('Unable to run HttpCore, no handler is set.'); |
82 | 82 | } |
83 | 83 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | callback: $callback, |
108 | 108 | attributes: [ |
109 | 109 | 'http.method' => $request->getMethod(), |
110 | - 'http.url' => (string) $request->getUri(), |
|
110 | + 'http.url' => (string)$request->getUri(), |
|
111 | 111 | 'http.headers' => \array_map( |
112 | 112 | static fn (array $values): string => \implode(',', $values), |
113 | 113 | $request->getHeaders(), |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | traceKind: TraceKind::SERVER, |
118 | 118 | ); |
119 | 119 | |
120 | - foreach ($tracer->getContext() as $key => $value) { |
|
120 | + foreach ($tracer->getContext() as $key => $value){ |
|
121 | 121 | $response = $response->withHeader($key, $value); |
122 | 122 | } |
123 | 123 |
@@ -35,11 +35,15 @@ discard block |
||
35 | 35 | ?TracerFactoryInterface $tracerFactory = null, |
36 | 36 | private readonly ?EventDispatcherInterface $dispatcher = null, |
37 | 37 | ) { |
38 | - if ($pipeline instanceof Pipeline) { |
|
39 | - foreach ($this->config->getMiddleware() as $middleware) { |
|
38 | + if ($pipeline instanceof Pipeline) |
|
39 | + { |
|
40 | + foreach ($this->config->getMiddleware() as $middleware) |
|
41 | + { |
|
40 | 42 | $pipeline->pushMiddleware($this->container->get($middleware)); |
41 | 43 | } |
42 | - } else { |
|
44 | + } |
|
45 | + else |
|
46 | + { |
|
43 | 47 | $pipeline = $pipeline->withAddedMiddleware( |
44 | 48 | ...$this->config->getMiddleware() |
45 | 49 | ); |
@@ -77,7 +81,8 @@ discard block |
||
77 | 81 | |
78 | 82 | $this->dispatcher?->dispatch(new RequestReceived($request)); |
79 | 83 | |
80 | - if ($this->handler === null) { |
|
84 | + if ($this->handler === null) |
|
85 | + { |
|
81 | 86 | throw new HttpException('Unable to run HttpCore, no handler is set.'); |
82 | 87 | } |
83 | 88 | |
@@ -117,7 +122,8 @@ discard block |
||
117 | 122 | traceKind: TraceKind::SERVER, |
118 | 123 | ); |
119 | 124 | |
120 | - foreach ($tracer->getContext() as $key => $value) { |
|
125 | + foreach ($tracer->getContext() as $key => $value) |
|
126 | + { |
|
121 | 127 | $response = $response->withHeader($key, $value); |
122 | 128 | } |
123 | 129 |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | $dispatcher |
55 | 55 | ->expects(self::exactly(2)) |
56 | 56 | ->method('dispatch') |
57 | - ->with($this->callback(static fn (Routing|RouteMatched $event): bool => $event->request instanceof ServerRequest)); |
|
57 | + ->with($this->callback(static fn (Routing | RouteMatched $event): bool => $event->request instanceof ServerRequest)); |
|
58 | 58 | |
59 | 59 | $router = $this->makeRouter('', $dispatcher); |
60 | 60 | $router->setDefault($route); |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $router->import($configurator); |
91 | 91 | $this->getContainer()->get(GroupRegistry::class)->registerRoutes($router); |
92 | 92 | |
93 | - $uri = (string) $router->uri('foo', ['host' => 'some']); |
|
93 | + $uri = (string)$router->uri('foo', ['host' => 'some']); |
|
94 | 94 | $this->assertSame('some/register', $uri); |
95 | 95 | $this->assertFalse(\str_contains('https://host.com', $uri)); |
96 | 96 | } |
@@ -46,11 +46,11 @@ discard block |
||
46 | 46 | private bool $isLegacyPipeline; |
47 | 47 | |
48 | 48 | public function __construct( |
49 | - private readonly HandlerInterface|CoreInterface $core, |
|
49 | + private readonly HandlerInterface | CoreInterface $core, |
|
50 | 50 | private readonly ScopeInterface $scope, |
51 | 51 | private readonly ResponseFactoryInterface $responseFactory, |
52 | 52 | ?TracerInterface $tracer = null |
53 | - ) { |
|
53 | + ){ |
|
54 | 54 | $this->tracer = $tracer ?? new NullTracer($scope); |
55 | 55 | $this->isLegacyPipeline = !$core instanceof HandlerInterface; |
56 | 56 | } |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | $output = ''; |
99 | 99 | |
100 | 100 | $response = $this->responseFactory->createResponse(200); |
101 | - try { |
|
101 | + try{ |
|
102 | 102 | $action = $this->verbActions |
103 | - ? \strtolower($request->getMethod()) . \ucfirst($this->action) |
|
103 | + ? \strtolower($request->getMethod()).\ucfirst($this->action) |
|
104 | 104 | : $this->action; |
105 | 105 | |
106 | 106 | // run the core withing PSR-7 Request/Response scope |
@@ -114,14 +114,14 @@ discard block |
||
114 | 114 | bindings: [Request::class => $request, Response::class => $response, $controller => $controller], |
115 | 115 | ), |
116 | 116 | fn (): mixed => $this->tracer->trace( |
117 | - name: 'Controller [' . $controller . ':' . $action . ']', |
|
117 | + name: 'Controller ['.$controller.':'.$action.']', |
|
118 | 118 | callback: $this->isLegacyPipeline |
119 | - ? fn (): mixed => $this->core->callAction( |
|
120 | - controller: $controller, |
|
121 | - action: $action, |
|
122 | - parameters: $parameters, |
|
119 | + ? fn () : mixed => $this->core->callAction( |
|
120 | + controller : $controller, |
|
121 | + action : $action, |
|
122 | + parameters : $parameters, |
|
123 | 123 | ) |
124 | - : fn (): mixed => $this->core->handle( |
|
124 | + : fn () : mixed => $this->core->handle( |
|
125 | 125 | new CallContext( |
126 | 126 | Target::fromPair($controller, $action), |
127 | 127 | $parameters, |
@@ -130,29 +130,29 @@ discard block |
||
130 | 130 | ], |
131 | 131 | ), |
132 | 132 | ), |
133 | - attributes: [ |
|
133 | + attributes : [ |
|
134 | 134 | 'route.controller' => $this->controller, |
135 | 135 | 'route.action' => $action, |
136 | 136 | 'route.parameters' => \array_keys($parameters), |
137 | 137 | ] |
138 | 138 | ) |
139 | 139 | ); |
140 | - } catch (TargetCallException $e) { |
|
140 | + }catch (TargetCallException $e){ |
|
141 | 141 | \ob_get_clean(); |
142 | 142 | throw $this->mapException($e); |
143 | - } catch (\Throwable $e) { |
|
143 | + }catch (\Throwable $e){ |
|
144 | 144 | \ob_get_clean(); |
145 | 145 | throw $e; |
146 | - } finally { |
|
147 | - while (\ob_get_level() > $outputLevel + 1) { |
|
148 | - $output = \ob_get_clean() . $output; |
|
146 | + }finally{ |
|
147 | + while (\ob_get_level() > $outputLevel + 1){ |
|
148 | + $output = \ob_get_clean().$output; |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
152 | 152 | return $this->wrapResponse( |
153 | 153 | $response, |
154 | 154 | $result, |
155 | - \ob_get_clean() . $output, |
|
155 | + \ob_get_clean().$output, |
|
156 | 156 | ); |
157 | 157 | } |
158 | 158 | |
@@ -165,21 +165,21 @@ discard block |
||
165 | 165 | */ |
166 | 166 | private function wrapResponse(Response $response, mixed $result = null, string $output = ''): Response |
167 | 167 | { |
168 | - if ($result instanceof Response) { |
|
169 | - if ($output !== '' && $result->getBody()->isWritable()) { |
|
168 | + if ($result instanceof Response){ |
|
169 | + if ($output !== '' && $result->getBody()->isWritable()){ |
|
170 | 170 | $result->getBody()->write($output); |
171 | 171 | } |
172 | 172 | |
173 | 173 | return $result; |
174 | 174 | } |
175 | 175 | |
176 | - if ($result instanceof \Generator) { |
|
176 | + if ($result instanceof \Generator){ |
|
177 | 177 | return $response->withBody(new GeneratorStream($result)); |
178 | 178 | } |
179 | 179 | |
180 | - if (\is_array($result) || $result instanceof \JsonSerializable) { |
|
180 | + if (\is_array($result) || $result instanceof \JsonSerializable){ |
|
181 | 181 | $response = $this->writeJson($response, $result); |
182 | - } else { |
|
182 | + }else{ |
|
183 | 183 | $response->getBody()->write((string)$result); |
184 | 184 | } |
185 | 185 | |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | */ |
213 | 213 | private function checkValues(): void |
214 | 214 | { |
215 | - if ($this->controller === null) { |
|
215 | + if ($this->controller === null){ |
|
216 | 216 | throw new HandlerException('Controller and action pair are not set.'); |
217 | 217 | } |
218 | 218 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | { |
21 | 21 | use ContainerTrait; |
22 | 22 | |
23 | - protected Pipeline|LazyPipeline|null $pipeline = null; |
|
23 | + protected Pipeline | LazyPipeline | null $pipeline = null; |
|
24 | 24 | |
25 | 25 | /** @psalm-var array<array-key, MiddlewareType> */ |
26 | 26 | protected array $middleware = []; |
@@ -44,16 +44,16 @@ discard block |
||
44 | 44 | $route = clone $this; |
45 | 45 | |
46 | 46 | // array fallback |
47 | - if (\count($middleware) === 1 && \is_array($middleware[0])) { |
|
47 | + if (\count($middleware) === 1 && \is_array($middleware[0])){ |
|
48 | 48 | $middleware = $middleware[0]; |
49 | 49 | } |
50 | 50 | |
51 | 51 | /** @var MiddlewareType[] $middleware */ |
52 | - foreach ($middleware as $item) { |
|
52 | + foreach ($middleware as $item){ |
|
53 | 53 | $route->middleware[] = $item; |
54 | 54 | } |
55 | 55 | |
56 | - if ($route->pipeline !== null) { |
|
56 | + if ($route->pipeline !== null){ |
|
57 | 57 | $route->pipeline = $route->makeLazyPipeline(); |
58 | 58 | } |
59 | 59 | |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | protected function makePipeline(): Pipeline |
81 | 81 | { |
82 | 82 | \assert($this->container !== null); |
83 | - try { |
|
83 | + try{ |
|
84 | 84 | return $this->container |
85 | 85 | ->get(PipelineFactory::class) |
86 | 86 | ->createWithMiddleware($this->middleware); |
87 | - } catch (ContainerExceptionInterface $e) { |
|
87 | + }catch (ContainerExceptionInterface $e){ |
|
88 | 88 | throw new RouteException($e->getMessage(), $e->getCode(), $e); |
89 | 89 | } |
90 | 90 | } |
@@ -97,11 +97,11 @@ discard block |
||
97 | 97 | protected function makeLazyPipeline(): LazyPipeline |
98 | 98 | { |
99 | 99 | \assert($this->container !== null); |
100 | - try { |
|
100 | + try{ |
|
101 | 101 | /** @var LazyPipeline $pipeline */ |
102 | 102 | $pipeline = $this->container->get(LazyPipeline::class); |
103 | 103 | return $pipeline->withMiddleware(...$this->middleware); |
104 | - } catch (ContainerExceptionInterface $e) { |
|
104 | + }catch (ContainerExceptionInterface $e){ |
|
105 | 105 | throw new RouteException($e->getMessage(), $e->getCode(), $e); |
106 | 106 | } |
107 | 107 | } |
@@ -44,16 +44,19 @@ discard block |
||
44 | 44 | $route = clone $this; |
45 | 45 | |
46 | 46 | // array fallback |
47 | - if (\count($middleware) === 1 && \is_array($middleware[0])) { |
|
47 | + if (\count($middleware) === 1 && \is_array($middleware[0])) |
|
48 | + { |
|
48 | 49 | $middleware = $middleware[0]; |
49 | 50 | } |
50 | 51 | |
51 | 52 | /** @var MiddlewareType[] $middleware */ |
52 | - foreach ($middleware as $item) { |
|
53 | + foreach ($middleware as $item) |
|
54 | + { |
|
53 | 55 | $route->middleware[] = $item; |
54 | 56 | } |
55 | 57 | |
56 | - if ($route->pipeline !== null) { |
|
58 | + if ($route->pipeline !== null) |
|
59 | + { |
|
57 | 60 | $route->pipeline = $route->makeLazyPipeline(); |
58 | 61 | } |
59 | 62 | |
@@ -80,11 +83,14 @@ discard block |
||
80 | 83 | protected function makePipeline(): Pipeline |
81 | 84 | { |
82 | 85 | \assert($this->container !== null); |
83 | - try { |
|
86 | + try |
|
87 | + { |
|
84 | 88 | return $this->container |
85 | 89 | ->get(PipelineFactory::class) |
86 | 90 | ->createWithMiddleware($this->middleware); |
87 | - } catch (ContainerExceptionInterface $e) { |
|
91 | + } |
|
92 | + catch (ContainerExceptionInterface $e) |
|
93 | + { |
|
88 | 94 | throw new RouteException($e->getMessage(), $e->getCode(), $e); |
89 | 95 | } |
90 | 96 | } |
@@ -97,11 +103,14 @@ discard block |
||
97 | 103 | protected function makeLazyPipeline(): LazyPipeline |
98 | 104 | { |
99 | 105 | \assert($this->container !== null); |
100 | - try { |
|
106 | + try |
|
107 | + { |
|
101 | 108 | /** @var LazyPipeline $pipeline */ |
102 | 109 | $pipeline = $this->container->get(LazyPipeline::class); |
103 | 110 | return $pipeline->withMiddleware(...$this->middleware); |
104 | - } catch (ContainerExceptionInterface $e) { |
|
111 | + } |
|
112 | + catch (ContainerExceptionInterface $e) |
|
113 | + { |
|
105 | 114 | throw new RouteException($e->getMessage(), $e->getCode(), $e); |
106 | 115 | } |
107 | 116 | } |
@@ -51,9 +51,9 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function __construct( |
53 | 53 | string $pattern, |
54 | - string|callable|RequestHandlerInterface|TargetInterface $target, |
|
54 | + string | callable | RequestHandlerInterface | TargetInterface $target, |
|
55 | 55 | array $defaults = [] |
56 | - ) { |
|
56 | + ){ |
|
57 | 57 | parent::__construct( |
58 | 58 | $pattern, |
59 | 59 | $target instanceof TargetInterface |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function withUriHandler(UriHandler $uriHandler): static |
71 | 71 | { |
72 | - if ($this->target instanceof TargetInterface) { |
|
72 | + if ($this->target instanceof TargetInterface){ |
|
73 | 73 | $uriHandler = $uriHandler->withConstrains( |
74 | 74 | $this->target->getConstrains(), |
75 | 75 | $this->defaults, |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | $route = clone $this; |
88 | 88 | $route->container = $container; |
89 | 89 | |
90 | - if ($route->target instanceof TargetInterface) { |
|
90 | + if ($route->target instanceof TargetInterface){ |
|
91 | 91 | $route->target = clone $route->target; |
92 | 92 | } |
93 | 93 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | */ |
115 | 115 | public function handle(ServerRequestInterface $request): ResponseInterface |
116 | 116 | { |
117 | - if (empty($this->requestHandler)) { |
|
117 | + if (empty($this->requestHandler)){ |
|
118 | 118 | $this->requestHandler = $this->requestHandler(); |
119 | 119 | } |
120 | 120 | |
@@ -134,25 +134,25 @@ discard block |
||
134 | 134 | 'Unable to configure route pipeline without associated container.', |
135 | 135 | ); |
136 | 136 | |
137 | - if ($this->target instanceof TargetInterface) { |
|
138 | - try { |
|
137 | + if ($this->target instanceof TargetInterface){ |
|
138 | + try{ |
|
139 | 139 | \assert($this->matches !== null); |
140 | 140 | return $this->target->getHandler($this->container, $this->matches); |
141 | - } catch (TargetException $e) { |
|
141 | + }catch (TargetException $e){ |
|
142 | 142 | throw new RouteException('Invalid target resolution', $e->getCode(), $e); |
143 | 143 | } |
144 | 144 | } |
145 | 145 | |
146 | - if ($this->target instanceof RequestHandlerInterface) { |
|
146 | + if ($this->target instanceof RequestHandlerInterface){ |
|
147 | 147 | return $this->target; |
148 | 148 | } |
149 | 149 | |
150 | - try { |
|
150 | + try{ |
|
151 | 151 | $target = \is_string($this->target) |
152 | 152 | ? $this->container->get($this->target) |
153 | 153 | : $this->target; |
154 | 154 | |
155 | - if ($target instanceof RequestHandlerInterface) { |
|
155 | + if ($target instanceof RequestHandlerInterface){ |
|
156 | 156 | return $target; |
157 | 157 | } |
158 | 158 | |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | $target, |
161 | 161 | $this->container->get(ResponseFactoryInterface::class) |
162 | 162 | ); |
163 | - } catch (ContainerExceptionInterface $e) { |
|
163 | + }catch (ContainerExceptionInterface $e){ |
|
164 | 164 | throw new RouteException($e->getMessage(), $e->getCode(), $e); |
165 | 165 | } |
166 | 166 | } |
@@ -69,7 +69,8 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function withUriHandler(UriHandler $uriHandler): static |
71 | 71 | { |
72 | - if ($this->target instanceof TargetInterface) { |
|
72 | + if ($this->target instanceof TargetInterface) |
|
73 | + { |
|
73 | 74 | $uriHandler = $uriHandler->withConstrains( |
74 | 75 | $this->target->getConstrains(), |
75 | 76 | $this->defaults, |
@@ -87,7 +88,8 @@ discard block |
||
87 | 88 | $route = clone $this; |
88 | 89 | $route->container = $container; |
89 | 90 | |
90 | - if ($route->target instanceof TargetInterface) { |
|
91 | + if ($route->target instanceof TargetInterface) |
|
92 | + { |
|
91 | 93 | $route->target = clone $route->target; |
92 | 94 | } |
93 | 95 | |
@@ -114,7 +116,8 @@ discard block |
||
114 | 116 | */ |
115 | 117 | public function handle(ServerRequestInterface $request): ResponseInterface |
116 | 118 | { |
117 | - if (empty($this->requestHandler)) { |
|
119 | + if (empty($this->requestHandler)) |
|
120 | + { |
|
118 | 121 | $this->requestHandler = $this->requestHandler(); |
119 | 122 | } |
120 | 123 | |
@@ -134,25 +137,32 @@ discard block |
||
134 | 137 | 'Unable to configure route pipeline without associated container.', |
135 | 138 | ); |
136 | 139 | |
137 | - if ($this->target instanceof TargetInterface) { |
|
138 | - try { |
|
140 | + if ($this->target instanceof TargetInterface) |
|
141 | + { |
|
142 | + try |
|
143 | + { |
|
139 | 144 | \assert($this->matches !== null); |
140 | 145 | return $this->target->getHandler($this->container, $this->matches); |
141 | - } catch (TargetException $e) { |
|
146 | + } |
|
147 | + catch (TargetException $e) |
|
148 | + { |
|
142 | 149 | throw new RouteException('Invalid target resolution', $e->getCode(), $e); |
143 | 150 | } |
144 | 151 | } |
145 | 152 | |
146 | - if ($this->target instanceof RequestHandlerInterface) { |
|
153 | + if ($this->target instanceof RequestHandlerInterface) |
|
154 | + { |
|
147 | 155 | return $this->target; |
148 | 156 | } |
149 | 157 | |
150 | - try { |
|
158 | + try |
|
159 | + { |
|
151 | 160 | $target = \is_string($this->target) |
152 | 161 | ? $this->container->get($this->target) |
153 | 162 | : $this->target; |
154 | 163 | |
155 | - if ($target instanceof RequestHandlerInterface) { |
|
164 | + if ($target instanceof RequestHandlerInterface) |
|
165 | + { |
|
156 | 166 | return $target; |
157 | 167 | } |
158 | 168 | |
@@ -160,7 +170,9 @@ discard block |
||
160 | 170 | $target, |
161 | 171 | $this->container->get(ResponseFactoryInterface::class) |
162 | 172 | ); |
163 | - } catch (ContainerExceptionInterface $e) { |
|
173 | + } |
|
174 | + catch (ContainerExceptionInterface $e) |
|
175 | + { |
|
164 | 176 | throw new RouteException($e->getMessage(), $e->getCode(), $e); |
165 | 177 | } |
166 | 178 | } |