@@ -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,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 |
@@ -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 |
@@ -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 | } |
@@ -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 |
@@ -63,7 +63,8 @@ discard block |
||
63 | 63 | |
64 | 64 | protected function resolveArguments(\ReflectionMethod $method, array $parameters): array |
65 | 65 | { |
66 | - foreach ($method->getParameters() as $parameter) { |
|
66 | + foreach ($method->getParameters() as $parameter) |
|
67 | + { |
|
67 | 68 | $name = $parameter->getName(); |
68 | 69 | if ( |
69 | 70 | \array_key_exists($name, $parameters) && |
@@ -84,9 +85,12 @@ discard block |
||
84 | 85 | */ |
85 | 86 | private function invoke(string $class, \ReflectionMethod $method, array $arguments): mixed |
86 | 87 | { |
87 | - try { |
|
88 | + try |
|
89 | + { |
|
88 | 90 | $args = $this->resolveArguments($method, $arguments); |
89 | - } catch (ArgumentResolvingException | InvalidArgumentException $e) { |
|
91 | + } |
|
92 | + catch (ArgumentResolvingException | InvalidArgumentException $e) |
|
93 | + { |
|
90 | 94 | throw new ControllerException( |
91 | 95 | \sprintf( |
92 | 96 | 'Missing/invalid parameter %s of `%s`->`%s`', |
@@ -97,7 +101,9 @@ discard block |
||
97 | 101 | ControllerException::BAD_ARGUMENT, |
98 | 102 | $e, |
99 | 103 | ); |
100 | - } catch (ContainerExceptionInterface $e) { |
|
104 | + } |
|
105 | + catch (ContainerExceptionInterface $e) |
|
106 | + { |
|
101 | 107 | throw new ControllerException( |
102 | 108 | $e->getMessage(), |
103 | 109 | ControllerException::ERROR, |
@@ -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 |
@@ -54,7 +54,8 @@ |
||
54 | 54 | |
55 | 55 | private function cookieQueue(?ServerRequestInterface $request): CookieQueue |
56 | 56 | { |
57 | - if ($request === null) { |
|
57 | + if ($request === null) |
|
58 | + { |
|
58 | 59 | throw new InvalidRequestScopeException(CookieQueue::class); |
59 | 60 | } |
60 | 61 |
@@ -33,7 +33,8 @@ |
||
33 | 33 | $request |
34 | 34 | ->expects($this->exactly(2)) |
35 | 35 | ->method('withAttribute') |
36 | - ->willReturnCallback(function (string $key, string $value) use ($matcher, $tokenStorage) { |
|
36 | + ->willReturnCallback(function (string $key, string $value) use ($matcher, $tokenStorage) |
|
37 | + { |
|
37 | 38 | match ($matcher->numberOfInvocations()) { |
38 | 39 | 1 => $this->assertInstanceOf(AuthContextInterface::class, $value), |
39 | 40 | 2 => $this->assertSame($tokenStorage, $value), |