@@ -20,20 +20,20 @@ |
||
20 | 20 | |
21 | 21 | public function __construct( |
22 | 22 | #[Proxy] protected InvokerInterface $invoker, |
23 | - ) { |
|
23 | + ){ |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | public function handle(string $name, string $id, mixed $payload, array $headers = []): void |
27 | 27 | { |
28 | - try { |
|
28 | + try{ |
|
29 | 29 | $params = ['payload' => $payload, 'id' => $id, 'headers' => $headers]; |
30 | 30 | |
31 | - if (\is_array($payload)) { |
|
31 | + if (\is_array($payload)){ |
|
32 | 32 | $params = \array_merge($params, $payload); |
33 | 33 | } |
34 | 34 | |
35 | 35 | $this->invoker->invoke([$this, $this->getHandlerMethod()], $params); |
36 | - } catch (\Throwable $e) { |
|
36 | + }catch (\Throwable $e){ |
|
37 | 37 | $message = \sprintf('[%s] %s', $this::class, $e->getMessage()); |
38 | 38 | throw new JobException($message, (int)$e->getCode(), $e); |
39 | 39 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | { |
47 | 47 | $core = $this->getCore(); |
48 | 48 | |
49 | - $core->setHandler(function () { |
|
49 | + $core->setHandler(function (){ |
|
50 | 50 | return 'hello world'; |
51 | 51 | }); |
52 | 52 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | { |
69 | 69 | $core = $this->getCore(); |
70 | 70 | $core->setHandler( |
71 | - new CallableHandler(function () { |
|
71 | + new CallableHandler(function (){ |
|
72 | 72 | return 'hello world'; |
73 | 73 | }, new ResponseFactory(new HttpConfig(['headers' => []]))) |
74 | 74 | ); |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | { |
82 | 82 | $core = $this->getCore(); |
83 | 83 | |
84 | - $core->setHandler(function ($req, $resp) { |
|
84 | + $core->setHandler(function ($req, $resp){ |
|
85 | 85 | return $resp->withAddedHeader('hello', 'value'); |
86 | 86 | }); |
87 | 87 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | { |
95 | 95 | $core = $this->getCore(); |
96 | 96 | |
97 | - $core->setHandler(function ($req, $resp) { |
|
97 | + $core->setHandler(function ($req, $resp){ |
|
98 | 98 | echo 'hello!'; |
99 | 99 | |
100 | 100 | return $resp->withAddedHeader('hello', 'value'); |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | { |
111 | 111 | $core = $this->getCore(); |
112 | 112 | |
113 | - $core->setHandler(function ($req, $resp) { |
|
113 | + $core->setHandler(function ($req, $resp){ |
|
114 | 114 | echo 'hello!'; |
115 | 115 | $resp->getBody()->write('world '); |
116 | 116 | |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | { |
128 | 128 | $core = $this->getCore(); |
129 | 129 | |
130 | - $core->setHandler(function () { |
|
130 | + $core->setHandler(function (){ |
|
131 | 131 | ob_start(); |
132 | 132 | ob_start(); |
133 | 133 | echo 'hello!'; |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | { |
149 | 149 | $core = $this->getCore(); |
150 | 150 | |
151 | - $core->setHandler(function () { |
|
151 | + $core->setHandler(function (){ |
|
152 | 152 | return [ |
153 | 153 | 'status' => 404, |
154 | 154 | 'message' => 'not found', |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | { |
165 | 165 | $core = $this->getCore(); |
166 | 166 | |
167 | - $core->setHandler(function () { |
|
167 | + $core->setHandler(function (){ |
|
168 | 168 | return new Json([ |
169 | 169 | 'status' => 404, |
170 | 170 | 'message' => 'not found', |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | { |
181 | 181 | $core = $this->getCore([HeaderMiddleware::class]); |
182 | 182 | |
183 | - $core->setHandler(function () { |
|
183 | + $core->setHandler(function (){ |
|
184 | 184 | return 'hello?'; |
185 | 185 | }); |
186 | 186 | |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | $core->getPipeline()->pushMiddleware(new Header2Middleware()); |
198 | 198 | $core->getPipeline()->riseMiddleware(new HeaderMiddleware()); |
199 | 199 | |
200 | - $core->setHandler(function () { |
|
200 | + $core->setHandler(function (){ |
|
201 | 201 | return 'hello?'; |
202 | 202 | }); |
203 | 203 | |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | $core->getPipeline()->pushMiddleware(new HeaderMiddleware()); |
215 | 215 | $core->getPipeline()->riseMiddleware(new Header2Middleware()); |
216 | 216 | |
217 | - $core->setHandler(function () { |
|
217 | + $core->setHandler(function (){ |
|
218 | 218 | return 'hello?'; |
219 | 219 | }); |
220 | 220 | |
@@ -247,12 +247,12 @@ discard block |
||
247 | 247 | $dispatcher |
248 | 248 | ->expects(self::exactly(2)) |
249 | 249 | ->method('dispatch') |
250 | - ->with($this->callback(static fn(RequestReceived|RequestHandled $event): bool => true)); |
|
250 | + ->with($this->callback(static fn(RequestReceived | RequestHandled $event): bool => true)); |
|
251 | 251 | $this->container->bind(EventDispatcherInterface::class, $dispatcher); |
252 | 252 | |
253 | 253 | $core = $this->getCore(); |
254 | 254 | |
255 | - $core->setHandler(function () { |
|
255 | + $core->setHandler(function (){ |
|
256 | 256 | return 'hello world'; |
257 | 257 | }); |
258 | 258 | |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | $tracerFactory = m::mock(TracerFactoryInterface::class), |
274 | 274 | ); |
275 | 275 | |
276 | - $http->setHandler(function () { |
|
276 | + $http->setHandler(function (){ |
|
277 | 277 | return 'hello world'; |
278 | 278 | }); |
279 | 279 |
@@ -46,7 +46,8 @@ discard block |
||
46 | 46 | { |
47 | 47 | $core = $this->getCore(); |
48 | 48 | |
49 | - $core->setHandler(function () { |
|
49 | + $core->setHandler(function () |
|
50 | + { |
|
50 | 51 | return 'hello world'; |
51 | 52 | }); |
52 | 53 | |
@@ -68,7 +69,8 @@ discard block |
||
68 | 69 | { |
69 | 70 | $core = $this->getCore(); |
70 | 71 | $core->setHandler( |
71 | - new CallableHandler(function () { |
|
72 | + new CallableHandler(function () |
|
73 | + { |
|
72 | 74 | return 'hello world'; |
73 | 75 | }, new ResponseFactory(new HttpConfig(['headers' => []]))) |
74 | 76 | ); |
@@ -81,7 +83,8 @@ discard block |
||
81 | 83 | { |
82 | 84 | $core = $this->getCore(); |
83 | 85 | |
84 | - $core->setHandler(function ($req, $resp) { |
|
86 | + $core->setHandler(function ($req, $resp) |
|
87 | + { |
|
85 | 88 | return $resp->withAddedHeader('hello', 'value'); |
86 | 89 | }); |
87 | 90 | |
@@ -94,7 +97,8 @@ discard block |
||
94 | 97 | { |
95 | 98 | $core = $this->getCore(); |
96 | 99 | |
97 | - $core->setHandler(function ($req, $resp) { |
|
100 | + $core->setHandler(function ($req, $resp) |
|
101 | + { |
|
98 | 102 | echo 'hello!'; |
99 | 103 | |
100 | 104 | return $resp->withAddedHeader('hello', 'value'); |
@@ -110,7 +114,8 @@ discard block |
||
110 | 114 | { |
111 | 115 | $core = $this->getCore(); |
112 | 116 | |
113 | - $core->setHandler(function ($req, $resp) { |
|
117 | + $core->setHandler(function ($req, $resp) |
|
118 | + { |
|
114 | 119 | echo 'hello!'; |
115 | 120 | $resp->getBody()->write('world '); |
116 | 121 | |
@@ -127,7 +132,8 @@ discard block |
||
127 | 132 | { |
128 | 133 | $core = $this->getCore(); |
129 | 134 | |
130 | - $core->setHandler(function () { |
|
135 | + $core->setHandler(function () |
|
136 | + { |
|
131 | 137 | ob_start(); |
132 | 138 | ob_start(); |
133 | 139 | echo 'hello!'; |
@@ -148,7 +154,8 @@ discard block |
||
148 | 154 | { |
149 | 155 | $core = $this->getCore(); |
150 | 156 | |
151 | - $core->setHandler(function () { |
|
157 | + $core->setHandler(function () |
|
158 | + { |
|
152 | 159 | return [ |
153 | 160 | 'status' => 404, |
154 | 161 | 'message' => 'not found', |
@@ -164,7 +171,8 @@ discard block |
||
164 | 171 | { |
165 | 172 | $core = $this->getCore(); |
166 | 173 | |
167 | - $core->setHandler(function () { |
|
174 | + $core->setHandler(function () |
|
175 | + { |
|
168 | 176 | return new Json([ |
169 | 177 | 'status' => 404, |
170 | 178 | 'message' => 'not found', |
@@ -180,7 +188,8 @@ discard block |
||
180 | 188 | { |
181 | 189 | $core = $this->getCore([HeaderMiddleware::class]); |
182 | 190 | |
183 | - $core->setHandler(function () { |
|
191 | + $core->setHandler(function () |
|
192 | + { |
|
184 | 193 | return 'hello?'; |
185 | 194 | }); |
186 | 195 | |
@@ -197,7 +206,8 @@ discard block |
||
197 | 206 | $core->getPipeline()->pushMiddleware(new Header2Middleware()); |
198 | 207 | $core->getPipeline()->riseMiddleware(new HeaderMiddleware()); |
199 | 208 | |
200 | - $core->setHandler(function () { |
|
209 | + $core->setHandler(function () |
|
210 | + { |
|
201 | 211 | return 'hello?'; |
202 | 212 | }); |
203 | 213 | |
@@ -214,7 +224,8 @@ discard block |
||
214 | 224 | $core->getPipeline()->pushMiddleware(new HeaderMiddleware()); |
215 | 225 | $core->getPipeline()->riseMiddleware(new Header2Middleware()); |
216 | 226 | |
217 | - $core->setHandler(function () { |
|
227 | + $core->setHandler(function () |
|
228 | + { |
|
218 | 229 | return 'hello?'; |
219 | 230 | }); |
220 | 231 | |
@@ -252,7 +263,8 @@ discard block |
||
252 | 263 | |
253 | 264 | $core = $this->getCore(); |
254 | 265 | |
255 | - $core->setHandler(function () { |
|
266 | + $core->setHandler(function () |
|
267 | + { |
|
256 | 268 | return 'hello world'; |
257 | 269 | }); |
258 | 270 | |
@@ -273,7 +285,8 @@ discard block |
||
273 | 285 | $tracerFactory = m::mock(TracerFactoryInterface::class), |
274 | 286 | ); |
275 | 287 | |
276 | - $http->setHandler(function () { |
|
288 | + $http->setHandler(function () |
|
289 | + { |
|
277 | 290 | return 'hello world'; |
278 | 291 | }); |
279 | 292 |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | { |
29 | 29 | $pipeline = new Pipeline($this->container); |
30 | 30 | |
31 | - $handler = new CallableHandler(function () { |
|
31 | + $handler = new CallableHandler(function (){ |
|
32 | 32 | return 'response'; |
33 | 33 | }, new ResponseFactory(new HttpConfig(['headers' => []]))); |
34 | 34 | |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | { |
44 | 44 | $pipeline = new Pipeline($this->container); |
45 | 45 | |
46 | - $handler = new CallableHandler(function () { |
|
46 | + $handler = new CallableHandler(function (){ |
|
47 | 47 | return 'response'; |
48 | 48 | }, new ResponseFactory(new HttpConfig(['headers' => []]))); |
49 | 49 | |
@@ -64,14 +64,14 @@ discard block |
||
64 | 64 | |
65 | 65 | public function testMiddlewareProcessingEventShouldBeDispatched(): void |
66 | 66 | { |
67 | - $middleware = new class implements MiddlewareInterface { |
|
67 | + $middleware = new class implements MiddlewareInterface{ |
|
68 | 68 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
69 | 69 | { |
70 | 70 | return (new ResponseFactory(new HttpConfig(['headers' => []])))->createResponse(200); |
71 | 71 | } |
72 | 72 | }; |
73 | 73 | $request = new ServerRequest('GET', ''); |
74 | - $handler = new CallableHandler(function () { |
|
74 | + $handler = new CallableHandler(function (){ |
|
75 | 75 | return 'response'; |
76 | 76 | }, new ResponseFactory(new HttpConfig(['headers' => []]))); |
77 | 77 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $this->container->getBinder('http') |
96 | 96 | ->bind(ServerRequestInterface::class, static fn(CurrentRequest $cr) => $cr->get()); |
97 | 97 | |
98 | - $middleware = new class implements MiddlewareInterface { |
|
98 | + $middleware = new class implements MiddlewareInterface{ |
|
99 | 99 | public function process( |
100 | 100 | ServerRequestInterface $request, |
101 | 101 | RequestHandlerInterface $handler, |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | new \Spiral\Core\Scope(name: 'http'), |
116 | 116 | function (ScopeInterface $c) use ($middleware) { |
117 | 117 | $request = new ServerRequest('GET', ''); |
118 | - $handler = new CallableHandler(function () { |
|
118 | + $handler = new CallableHandler(function (){ |
|
119 | 119 | return 'response'; |
120 | 120 | }, new ResponseFactory(new HttpConfig(['headers' => []]))); |
121 | 121 |
@@ -28,7 +28,8 @@ discard block |
||
28 | 28 | { |
29 | 29 | $pipeline = new Pipeline($this->container); |
30 | 30 | |
31 | - $handler = new CallableHandler(function () { |
|
31 | + $handler = new CallableHandler(function () |
|
32 | + { |
|
32 | 33 | return 'response'; |
33 | 34 | }, new ResponseFactory(new HttpConfig(['headers' => []]))); |
34 | 35 | |
@@ -43,7 +44,8 @@ discard block |
||
43 | 44 | { |
44 | 45 | $pipeline = new Pipeline($this->container); |
45 | 46 | |
46 | - $handler = new CallableHandler(function () { |
|
47 | + $handler = new CallableHandler(function () |
|
48 | + { |
|
47 | 49 | return 'response'; |
48 | 50 | }, new ResponseFactory(new HttpConfig(['headers' => []]))); |
49 | 51 | |
@@ -64,14 +66,16 @@ discard block |
||
64 | 66 | |
65 | 67 | public function testMiddlewareProcessingEventShouldBeDispatched(): void |
66 | 68 | { |
67 | - $middleware = new class implements MiddlewareInterface { |
|
69 | + $middleware = new class implements MiddlewareInterface |
|
70 | + { |
|
68 | 71 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
69 | 72 | { |
70 | 73 | return (new ResponseFactory(new HttpConfig(['headers' => []])))->createResponse(200); |
71 | 74 | } |
72 | 75 | }; |
73 | 76 | $request = new ServerRequest('GET', ''); |
74 | - $handler = new CallableHandler(function () { |
|
77 | + $handler = new CallableHandler(function () |
|
78 | + { |
|
75 | 79 | return 'response'; |
76 | 80 | }, new ResponseFactory(new HttpConfig(['headers' => []]))); |
77 | 81 | |
@@ -95,7 +99,8 @@ discard block |
||
95 | 99 | $this->container->getBinder('http') |
96 | 100 | ->bind(ServerRequestInterface::class, static fn(CurrentRequest $cr) => $cr->get()); |
97 | 101 | |
98 | - $middleware = new class implements MiddlewareInterface { |
|
102 | + $middleware = new class implements MiddlewareInterface |
|
103 | + { |
|
99 | 104 | public function process( |
100 | 105 | ServerRequestInterface $request, |
101 | 106 | RequestHandlerInterface $handler, |
@@ -113,9 +118,11 @@ discard block |
||
113 | 118 | |
114 | 119 | $this->container->runScope( |
115 | 120 | new \Spiral\Core\Scope(name: 'http'), |
116 | - function (ScopeInterface $c) use ($middleware) { |
|
121 | + function (ScopeInterface $c) use ($middleware) |
|
122 | + { |
|
117 | 123 | $request = new ServerRequest('GET', ''); |
118 | - $handler = new CallableHandler(function () { |
|
124 | + $handler = new CallableHandler(function () |
|
125 | + { |
|
119 | 126 | return 'response'; |
120 | 127 | }, new ResponseFactory(new HttpConfig(['headers' => []]))); |
121 | 128 |
@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | private readonly ContainerInterface $container, |
34 | 34 | ?TracerFactoryInterface $tracerFactory = null, |
35 | 35 | private readonly ?EventDispatcherInterface $dispatcher = null, |
36 | - ) { |
|
37 | - foreach ($this->config->getMiddleware() as $middleware) { |
|
36 | + ){ |
|
37 | + foreach ($this->config->getMiddleware() as $middleware){ |
|
38 | 38 | $this->pipeline->pushMiddleware($this->container->get($middleware)); |
39 | 39 | } |
40 | 40 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | return $this->pipeline; |
48 | 48 | } |
49 | 49 | |
50 | - public function setHandler(callable|RequestHandlerInterface $handler): self |
|
50 | + public function setHandler(callable | RequestHandlerInterface $handler): self |
|
51 | 51 | { |
52 | 52 | $this->handler = $handler instanceof RequestHandlerInterface |
53 | 53 | ? $handler |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | |
67 | 67 | $this->dispatcher?->dispatch(new RequestReceived($request)); |
68 | 68 | |
69 | - if ($this->handler === null) { |
|
69 | + if ($this->handler === null){ |
|
70 | 70 | throw new HttpException('Unable to run HttpCore, no handler is set.'); |
71 | 71 | } |
72 | 72 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | traceKind: TraceKind::SERVER |
104 | 104 | ); |
105 | 105 | |
106 | - foreach ($tracer->getContext() as $key => $value) { |
|
106 | + foreach ($tracer->getContext() as $key => $value){ |
|
107 | 107 | $response = $response->withHeader($key, $value); |
108 | 108 | } |
109 | 109 |
@@ -34,7 +34,8 @@ discard block |
||
34 | 34 | ?TracerFactoryInterface $tracerFactory = null, |
35 | 35 | private readonly ?EventDispatcherInterface $dispatcher = null, |
36 | 36 | ) { |
37 | - foreach ($this->config->getMiddleware() as $middleware) { |
|
37 | + foreach ($this->config->getMiddleware() as $middleware) |
|
38 | + { |
|
38 | 39 | $this->pipeline->pushMiddleware($this->container->get($middleware)); |
39 | 40 | } |
40 | 41 | |
@@ -66,7 +67,8 @@ discard block |
||
66 | 67 | |
67 | 68 | $this->dispatcher?->dispatch(new RequestReceived($request)); |
68 | 69 | |
69 | - if ($this->handler === null) { |
|
70 | + if ($this->handler === null) |
|
71 | + { |
|
70 | 72 | throw new HttpException('Unable to run HttpCore, no handler is set.'); |
71 | 73 | } |
72 | 74 | |
@@ -103,7 +105,8 @@ discard block |
||
103 | 105 | traceKind: TraceKind::SERVER |
104 | 106 | ); |
105 | 107 | |
106 | - foreach ($tracer->getContext() as $key => $value) { |
|
108 | + foreach ($tracer->getContext() as $key => $value) |
|
109 | + { |
|
107 | 110 | $response = $response->withHeader($key, $value); |
108 | 111 | } |
109 | 112 |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | #[Proxy] private readonly ScopeInterface $scope, |
35 | 35 | private readonly ?EventDispatcherInterface $dispatcher = null, |
36 | 36 | ?TracerInterface $tracer = null |
37 | - ) { |
|
37 | + ){ |
|
38 | 38 | $this->tracer = $tracer ?? new NullTracer($scope); |
39 | 39 | } |
40 | 40 | |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | |
60 | 60 | public function handle(Request $request): Response |
61 | 61 | { |
62 | - if ($this->handler === null) { |
|
62 | + if ($this->handler === null){ |
|
63 | 63 | throw new PipelineException('Unable to run pipeline, no handler given.'); |
64 | 64 | } |
65 | 65 | |
@@ -69,9 +69,9 @@ discard block |
||
69 | 69 | |
70 | 70 | $previousRequest = $currentRequest?->get(); |
71 | 71 | $currentRequest?->set($request); |
72 | - try { |
|
72 | + try{ |
|
73 | 73 | $position = $this->position++; |
74 | - if (!isset($this->middleware[$position])) { |
|
74 | + if (!isset($this->middleware[$position])){ |
|
75 | 75 | return $this->handler->handle($request); |
76 | 76 | } |
77 | 77 | |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | ], |
104 | 104 | scoped: true |
105 | 105 | ); |
106 | - } finally { |
|
107 | - if ($previousRequest !== null) { |
|
106 | + }finally{ |
|
107 | + if ($previousRequest !== null){ |
|
108 | 108 | $currentRequest?->set($previousRequest); |
109 | 109 | } |
110 | 110 | } |
@@ -59,7 +59,8 @@ discard block |
||
59 | 59 | |
60 | 60 | public function handle(Request $request): Response |
61 | 61 | { |
62 | - if ($this->handler === null) { |
|
62 | + if ($this->handler === null) |
|
63 | + { |
|
63 | 64 | throw new PipelineException('Unable to run pipeline, no handler given.'); |
64 | 65 | } |
65 | 66 | |
@@ -69,9 +70,11 @@ discard block |
||
69 | 70 | |
70 | 71 | $previousRequest = $currentRequest?->get(); |
71 | 72 | $currentRequest?->set($request); |
72 | - try { |
|
73 | + try |
|
74 | + { |
|
73 | 75 | $position = $this->position++; |
74 | - if (!isset($this->middleware[$position])) { |
|
76 | + if (!isset($this->middleware[$position])) |
|
77 | + { |
|
75 | 78 | return $this->handler->handle($request); |
76 | 79 | } |
77 | 80 | |
@@ -103,8 +106,11 @@ discard block |
||
103 | 106 | ], |
104 | 107 | scoped: true |
105 | 108 | ); |
106 | - } finally { |
|
107 | - if ($previousRequest !== null) { |
|
109 | + } |
|
110 | + finally |
|
111 | + { |
|
112 | + if ($previousRequest !== null) |
|
113 | + { |
|
108 | 114 | $currentRequest?->set($previousRequest); |
109 | 115 | } |
110 | 116 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | #[Proxy] private readonly ContainerInterface $container, |
122 | 122 | /** @invisible */ |
123 | 123 | HttpConfig $config = new HttpConfig() |
124 | - ) { |
|
124 | + ){ |
|
125 | 125 | $this->bagAssociations = \array_merge($this->bagAssociations, $config->getInputBags()); |
126 | 126 | } |
127 | 127 | |
@@ -150,10 +150,10 @@ discard block |
||
150 | 150 | { |
151 | 151 | $input = clone $this; |
152 | 152 | |
153 | - if ($add) { |
|
154 | - $input->prefix .= '.' . $prefix; |
|
153 | + if ($add){ |
|
154 | + $input->prefix .= '.'.$prefix; |
|
155 | 155 | $input->prefix = \trim($input->prefix, '.'); |
156 | - } else { |
|
156 | + }else{ |
|
157 | 157 | $input->prefix = $prefix; |
158 | 158 | } |
159 | 159 | |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | |
170 | 170 | return match (true) { |
171 | 171 | empty($path) => '/', |
172 | - $path[0] !== '/' => '/' . $path, |
|
172 | + $path[0] !== '/' => '/'.$path, |
|
173 | 173 | default => $path |
174 | 174 | }; |
175 | 175 | } |
@@ -189,9 +189,9 @@ discard block |
||
189 | 189 | */ |
190 | 190 | public function request(): Request |
191 | 191 | { |
192 | - try { |
|
192 | + try{ |
|
193 | 193 | $request = $this->container->get(Request::class); |
194 | - } catch (ContainerExceptionInterface $e) { |
|
194 | + }catch (ContainerExceptionInterface $e){ |
|
195 | 195 | throw new ScopeException( |
196 | 196 | 'Unable to get `ServerRequestInterface` in active container scope', |
197 | 197 | $e->getCode(), |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | } |
201 | 201 | |
202 | 202 | // Flushing input state |
203 | - if ($this->request !== $request) { |
|
203 | + if ($this->request !== $request){ |
|
204 | 204 | $this->bags = []; |
205 | 205 | $this->request = $request; |
206 | 206 | } |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | |
218 | 218 | $position = \strrpos($header, 'Bearer '); |
219 | 219 | |
220 | - if ($position !== false) { |
|
220 | + if ($position !== false){ |
|
221 | 221 | $header = \substr($header, $position + 7); |
222 | 222 | |
223 | 223 | return \str_contains($header, ',') |
@@ -271,16 +271,16 @@ discard block |
||
271 | 271 | public function isJsonExpected(bool $softMatch = false): bool |
272 | 272 | { |
273 | 273 | $acceptHeader = AcceptHeader::fromString($this->request()->getHeaderLine('Accept')); |
274 | - foreach ($this->jsonTypes as $jsonType) { |
|
275 | - if ($acceptHeader->has($jsonType)) { |
|
274 | + foreach ($this->jsonTypes as $jsonType){ |
|
275 | + if ($acceptHeader->has($jsonType)){ |
|
276 | 276 | return true; |
277 | 277 | } |
278 | 278 | } |
279 | 279 | |
280 | - if ($softMatch) { |
|
281 | - foreach ($acceptHeader->getAll() as $item) { |
|
280 | + if ($softMatch){ |
|
281 | + foreach ($acceptHeader->getAll() as $item){ |
|
282 | 282 | $itemValue = \strtolower($item->getValue()); |
283 | - if (\str_ends_with($itemValue, '/json') || \str_ends_with($itemValue, '+json')) { |
|
283 | + if (\str_ends_with($itemValue, '/json') || \str_ends_with($itemValue, '+json')){ |
|
284 | 284 | return true; |
285 | 285 | } |
286 | 286 | } |
@@ -319,19 +319,19 @@ discard block |
||
319 | 319 | // ensure proper request association |
320 | 320 | $this->request(); |
321 | 321 | |
322 | - if (isset($this->bags[$name])) { |
|
322 | + if (isset($this->bags[$name])){ |
|
323 | 323 | return $this->bags[$name]; |
324 | 324 | } |
325 | 325 | |
326 | 326 | $definition = $this->findBagDefinition($name); |
327 | - if (!$definition) { |
|
327 | + if (!$definition){ |
|
328 | 328 | throw new InputException(\sprintf("Undefined input bag '%s'", $name)); |
329 | 329 | } |
330 | 330 | |
331 | 331 | $class = $definition['class']; |
332 | 332 | $data = \call_user_func([$this->request(), $definition['source']]); |
333 | 333 | |
334 | - if (!\is_array($data)) { |
|
334 | + if (!\is_array($data)){ |
|
335 | 335 | $data = (array)$data; |
336 | 336 | } |
337 | 337 | |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | |
341 | 341 | public function hasBag(string $name): bool |
342 | 342 | { |
343 | - if (isset($this->bags[$name])) { |
|
343 | + if (isset($this->bags[$name])){ |
|
344 | 344 | return true; |
345 | 345 | } |
346 | 346 | |
@@ -360,12 +360,12 @@ discard block |
||
360 | 360 | */ |
361 | 361 | private function findBagDefinition(string $name): ?array |
362 | 362 | { |
363 | - if (isset($this->bagAssociations[$name])) { |
|
363 | + if (isset($this->bagAssociations[$name])){ |
|
364 | 364 | return $this->bagAssociations[$name]; |
365 | 365 | } |
366 | 366 | |
367 | - foreach ($this->bagAssociations as $bag) { |
|
368 | - if (isset($bag['alias']) && $bag['alias'] === $name) { |
|
367 | + foreach ($this->bagAssociations as $bag){ |
|
368 | + if (isset($bag['alias']) && $bag['alias'] === $name){ |
|
369 | 369 | return $bag; |
370 | 370 | } |
371 | 371 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | /** @internal */ |
23 | 23 | protected ContainerInterface $container, |
24 | 24 | protected bool $resolveFromPath = true, |
25 | - ) { |
|
25 | + ){ |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -35,13 +35,13 @@ discard block |
||
35 | 35 | // Resolve controller method |
36 | 36 | $method = $context->getTarget()->getReflection(); |
37 | 37 | $path = $context->getTarget()->getPath(); |
38 | - if ($method === null) { |
|
38 | + if ($method === null){ |
|
39 | 39 | $this->resolveFromPath or throw new TargetCallException( |
40 | 40 | "Reflection not provided for target `{$context->getTarget()}`.", |
41 | 41 | TargetCallException::NOT_FOUND, |
42 | 42 | ); |
43 | 43 | |
44 | - if (\count($path) !== 2) { |
|
44 | + if (\count($path) !== 2){ |
|
45 | 45 | throw new TargetCallException( |
46 | 46 | "Invalid target path to resolve reflection for `{$context->getTarget()}`." |
47 | 47 | . ' Expected two parts: class and method.', |
@@ -52,13 +52,13 @@ discard block |
||
52 | 52 | $method = ActionResolver::pathToReflection(\reset($path), \next($path)); |
53 | 53 | } |
54 | 54 | |
55 | - if ($method instanceof \ReflectionFunction) { |
|
55 | + if ($method instanceof \ReflectionFunction){ |
|
56 | 56 | return $method->invokeArgs( |
57 | 57 | $this->resolveArguments($method, $context) |
58 | 58 | ); |
59 | 59 | } |
60 | 60 | |
61 | - if (!$method instanceof \ReflectionMethod) { |
|
61 | + if (!$method instanceof \ReflectionMethod){ |
|
62 | 62 | throw new TargetCallException("Action not found for target `{$context->getTarget()}`."); |
63 | 63 | } |
64 | 64 |
@@ -35,13 +35,15 @@ discard block |
||
35 | 35 | // Resolve controller method |
36 | 36 | $method = $context->getTarget()->getReflection(); |
37 | 37 | $path = $context->getTarget()->getPath(); |
38 | - if ($method === null) { |
|
38 | + if ($method === null) |
|
39 | + { |
|
39 | 40 | $this->resolveFromPath or throw new TargetCallException( |
40 | 41 | "Reflection not provided for target `{$context->getTarget()}`.", |
41 | 42 | TargetCallException::NOT_FOUND, |
42 | 43 | ); |
43 | 44 | |
44 | - if (\count($path) !== 2) { |
|
45 | + if (\count($path) !== 2) |
|
46 | + { |
|
45 | 47 | throw new TargetCallException( |
46 | 48 | "Invalid target path to resolve reflection for `{$context->getTarget()}`." |
47 | 49 | . ' Expected two parts: class and method.', |
@@ -52,13 +54,15 @@ discard block |
||
52 | 54 | $method = ActionResolver::pathToReflection(\reset($path), \next($path)); |
53 | 55 | } |
54 | 56 | |
55 | - if ($method instanceof \ReflectionFunction) { |
|
57 | + if ($method instanceof \ReflectionFunction) |
|
58 | + { |
|
56 | 59 | return $method->invokeArgs( |
57 | 60 | $this->resolveArguments($method, $context) |
58 | 61 | ); |
59 | 62 | } |
60 | 63 | |
61 | - if (!$method instanceof \ReflectionMethod) { |
|
64 | + if (!$method instanceof \ReflectionMethod) |
|
65 | + { |
|
62 | 66 | throw new TargetCallException("Action not found for target `{$context->getTarget()}`."); |
63 | 67 | } |
64 | 68 |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | |
23 | 23 | public function __construct( |
24 | 24 | #[Proxy] private readonly ContainerInterface $container |
25 | - ) { |
|
25 | + ){ |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -96,9 +96,9 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public function getActiveSession(): SessionInterface |
98 | 98 | { |
99 | - try { |
|
99 | + try{ |
|
100 | 100 | return $this->container->get(SessionInterface::class); |
101 | - } catch (NotFoundExceptionInterface $e) { |
|
101 | + }catch (NotFoundExceptionInterface $e){ |
|
102 | 102 | throw new ScopeException( |
103 | 103 | 'Unable to receive active session, invalid request scope', |
104 | 104 | $e->getCode(), |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | private readonly CookiesConfig $cookiesConfig, |
35 | 35 | private readonly SessionFactoryInterface $factory, |
36 | 36 | private readonly ScopeInterface $scope |
37 | - ) { |
|
37 | + ){ |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | $this->fetchID($request) |
49 | 49 | ); |
50 | 50 | |
51 | - try { |
|
51 | + try{ |
|
52 | 52 | $response = $handler->handle($request->withAttribute(self::ATTRIBUTE, $session)); |
53 | - } catch (\Throwable $e) { |
|
53 | + }catch (\Throwable $e){ |
|
54 | 54 | $session->abort(); |
55 | 55 | throw $e; |
56 | 56 | } |
@@ -63,14 +63,14 @@ discard block |
||
63 | 63 | Request $request, |
64 | 64 | Response $response |
65 | 65 | ): Response { |
66 | - if (!$session->isStarted()) { |
|
66 | + if (!$session->isStarted()){ |
|
67 | 67 | return $response; |
68 | 68 | } |
69 | 69 | |
70 | 70 | $session->commit(); |
71 | 71 | |
72 | 72 | //SID changed |
73 | - if ($this->fetchID($request) !== $session->getID()) { |
|
73 | + if ($this->fetchID($request) !== $session->getID()){ |
|
74 | 74 | return $this->withCookie($request, $response, $session->getID()); |
75 | 75 | } |
76 | 76 | |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | protected function fetchID(Request $request): ?string |
85 | 85 | { |
86 | 86 | $cookies = $request->getCookieParams(); |
87 | - if (empty($cookies[$this->config->getCookie()])) { |
|
87 | + if (empty($cookies[$this->config->getCookie()])){ |
|
88 | 88 | return null; |
89 | 89 | } |
90 | 90 | |
@@ -106,8 +106,8 @@ discard block |
||
106 | 106 | protected function clientSignature(Request $request): string |
107 | 107 | { |
108 | 108 | $signature = ''; |
109 | - foreach (self::SIGNATURE_HEADERS as $header) { |
|
110 | - $signature .= $request->getHeaderLine($header) . ';'; |
|
109 | + foreach (self::SIGNATURE_HEADERS as $header){ |
|
110 | + $signature .= $request->getHeaderLine($header).';'; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | return \hash('sha256', $signature); |
@@ -48,9 +48,12 @@ discard block |
||
48 | 48 | $this->fetchID($request) |
49 | 49 | ); |
50 | 50 | |
51 | - try { |
|
51 | + try |
|
52 | + { |
|
52 | 53 | $response = $handler->handle($request->withAttribute(self::ATTRIBUTE, $session)); |
53 | - } catch (\Throwable $e) { |
|
54 | + } |
|
55 | + catch (\Throwable $e) |
|
56 | + { |
|
54 | 57 | $session->abort(); |
55 | 58 | throw $e; |
56 | 59 | } |
@@ -63,14 +66,16 @@ discard block |
||
63 | 66 | Request $request, |
64 | 67 | Response $response |
65 | 68 | ): Response { |
66 | - if (!$session->isStarted()) { |
|
69 | + if (!$session->isStarted()) |
|
70 | + { |
|
67 | 71 | return $response; |
68 | 72 | } |
69 | 73 | |
70 | 74 | $session->commit(); |
71 | 75 | |
72 | 76 | //SID changed |
73 | - if ($this->fetchID($request) !== $session->getID()) { |
|
77 | + if ($this->fetchID($request) !== $session->getID()) |
|
78 | + { |
|
74 | 79 | return $this->withCookie($request, $response, $session->getID()); |
75 | 80 | } |
76 | 81 | |
@@ -84,7 +89,8 @@ discard block |
||
84 | 89 | protected function fetchID(Request $request): ?string |
85 | 90 | { |
86 | 91 | $cookies = $request->getCookieParams(); |
87 | - if (empty($cookies[$this->config->getCookie()])) { |
|
92 | + if (empty($cookies[$this->config->getCookie()])) |
|
93 | + { |
|
88 | 94 | return null; |
89 | 95 | } |
90 | 96 | |
@@ -106,7 +112,8 @@ discard block |
||
106 | 112 | protected function clientSignature(Request $request): string |
107 | 113 | { |
108 | 114 | $signature = ''; |
109 | - foreach (self::SIGNATURE_HEADERS as $header) { |
|
115 | + foreach (self::SIGNATURE_HEADERS as $header) |
|
116 | + { |
|
110 | 117 | $signature .= $request->getHeaderLine($header) . ';'; |
111 | 118 | } |
112 | 119 |