@@ -17,7 +17,7 @@ |
||
| 17 | 17 | { |
| 18 | 18 | public function __construct( |
| 19 | 19 | #[Proxy] private readonly ?ScopeInterface $scope = new Container(), |
| 20 | - ) { |
|
| 20 | + ){ |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | public function make(array $context = []): TracerInterface |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | { |
| 19 | 19 | public function __construct( |
| 20 | 20 | #[Proxy] private readonly ?ScopeInterface $scope = new Container(), |
| 21 | - ) { |
|
| 21 | + ){ |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -30,6 +30,6 @@ discard block |
||
| 30 | 30 | return $this->scope->runScope([ |
| 31 | 31 | SpanInterface::class => $span, |
| 32 | 32 | TracerInterface::class => $this, |
| 33 | - ], static fn (InvokerInterface $invoker): mixed => $invoker->invoke($callback)); |
|
| 33 | + ], static fn (InvokerInterface $invoker) : mixed => $invoker->invoke($callback)); |
|
| 34 | 34 | } |
| 35 | 35 | } |
@@ -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 | } |
@@ -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,42 +114,42 @@ 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, |
| 128 | 128 | ), |
| 129 | 129 | ), |
| 130 | - attributes: [ |
|
| 130 | + attributes : [ |
|
| 131 | 131 | 'route.controller' => $this->controller, |
| 132 | 132 | 'route.action' => $action, |
| 133 | 133 | 'route.parameters' => \array_keys($parameters), |
| 134 | 134 | ] |
| 135 | 135 | ) |
| 136 | 136 | ); |
| 137 | - } catch (TargetCallException $e) { |
|
| 137 | + }catch (TargetCallException $e){ |
|
| 138 | 138 | \ob_get_clean(); |
| 139 | 139 | throw $this->mapException($e); |
| 140 | - } catch (\Throwable $e) { |
|
| 140 | + }catch (\Throwable $e){ |
|
| 141 | 141 | \ob_get_clean(); |
| 142 | 142 | throw $e; |
| 143 | - } finally { |
|
| 144 | - while (\ob_get_level() > $outputLevel + 1) { |
|
| 145 | - $output = \ob_get_clean() . $output; |
|
| 143 | + }finally{ |
|
| 144 | + while (\ob_get_level() > $outputLevel + 1){ |
|
| 145 | + $output = \ob_get_clean().$output; |
|
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | return $this->wrapResponse( |
| 150 | 150 | $response, |
| 151 | 151 | $result, |
| 152 | - \ob_get_clean() . $output, |
|
| 152 | + \ob_get_clean().$output, |
|
| 153 | 153 | ); |
| 154 | 154 | } |
| 155 | 155 | |
@@ -162,21 +162,21 @@ discard block |
||
| 162 | 162 | */ |
| 163 | 163 | private function wrapResponse(Response $response, mixed $result = null, string $output = ''): Response |
| 164 | 164 | { |
| 165 | - if ($result instanceof Response) { |
|
| 166 | - if ($output !== '' && $result->getBody()->isWritable()) { |
|
| 165 | + if ($result instanceof Response){ |
|
| 166 | + if ($output !== '' && $result->getBody()->isWritable()){ |
|
| 167 | 167 | $result->getBody()->write($output); |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | return $result; |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - if ($result instanceof \Generator) { |
|
| 173 | + if ($result instanceof \Generator){ |
|
| 174 | 174 | return $response->withBody(new GeneratorStream($result)); |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - if (\is_array($result) || $result instanceof \JsonSerializable) { |
|
| 177 | + if (\is_array($result) || $result instanceof \JsonSerializable){ |
|
| 178 | 178 | $response = $this->writeJson($response, $result); |
| 179 | - } else { |
|
| 179 | + }else{ |
|
| 180 | 180 | $response->getBody()->write((string)$result); |
| 181 | 181 | } |
| 182 | 182 | |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | */ |
| 210 | 210 | private function checkValues(): void |
| 211 | 211 | { |
| 212 | - if ($this->controller === null) { |
|
| 212 | + if ($this->controller === null){ |
|
| 213 | 213 | throw new HandlerException('Controller and action pair are not set.'); |
| 214 | 214 | } |
| 215 | 215 | } |