@@ -14,13 +14,13 @@ |
||
14 | 14 | |
15 | 15 | public function __construct( |
16 | 16 | private readonly int $counter, |
17 | - ) { |
|
17 | + ){ |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | public function intercept(CallContextInterface $context, HandlerInterface $handler): mixed |
21 | 21 | { |
22 | 22 | $this->result = []; |
23 | - for ($i = 0; $i < $this->counter; ++$i) { |
|
23 | + for ($i = 0; $i < $this->counter; ++$i){ |
|
24 | 24 | $this->result[] = $handler->handle($context); |
25 | 25 | } |
26 | 26 |
@@ -20,7 +20,8 @@ |
||
20 | 20 | public function intercept(CallContextInterface $context, HandlerInterface $handler): mixed |
21 | 21 | { |
22 | 22 | $this->result = []; |
23 | - for ($i = 0; $i < $this->counter; ++$i) { |
|
23 | + for ($i = 0; $i < $this->counter; ++$i) |
|
24 | + { |
|
24 | 25 | $this->result[] = $handler->handle($context); |
25 | 26 | } |
26 | 27 |
@@ -19,10 +19,10 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public static function pathToReflection(string $controller, string $action): \ReflectionMethod |
21 | 21 | { |
22 | - try { |
|
22 | + try{ |
|
23 | 23 | /** @psalm-suppress ArgumentTypeCoercion */ |
24 | 24 | $method = new \ReflectionMethod($controller, $action); |
25 | - } catch (\ReflectionException $e) { |
|
25 | + }catch (\ReflectionException $e){ |
|
26 | 26 | throw new TargetCallException( |
27 | 27 | \sprintf('Invalid action `%s`->`%s`', $controller, $action), |
28 | 28 | TargetCallException::BAD_ACTION, |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public static function validateControllerMethod(\ReflectionMethod $method, mixed $controller = null): void |
41 | 41 | { |
42 | - if ($method->isStatic() || !$method->isPublic()) { |
|
42 | + if ($method->isStatic() || !$method->isPublic()){ |
|
43 | 43 | throw new TargetCallException( |
44 | 44 | \sprintf( |
45 | 45 | 'Invalid action `%s`->`%s`', |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | ); |
51 | 51 | } |
52 | 52 | |
53 | - if ($controller === null) { |
|
53 | + if ($controller === null){ |
|
54 | 54 | return; |
55 | 55 | } |
56 | 56 | |
57 | - if (!\is_object($controller) || !$method->getDeclaringClass()->isInstance($controller)) { |
|
57 | + if (!\is_object($controller) || !$method->getDeclaringClass()->isInstance($controller)){ |
|
58 | 58 | throw new TargetCallException( |
59 | 59 | \sprintf( |
60 | 60 | 'Invalid controller. Expected instance of `%s`, got `%s`.', |
@@ -19,10 +19,13 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public static function pathToReflection(string $controller, string $action): \ReflectionMethod |
21 | 21 | { |
22 | - try { |
|
22 | + try |
|
23 | + { |
|
23 | 24 | /** @psalm-suppress ArgumentTypeCoercion */ |
24 | 25 | $method = new \ReflectionMethod($controller, $action); |
25 | - } catch (\ReflectionException $e) { |
|
26 | + } |
|
27 | + catch (\ReflectionException $e) |
|
28 | + { |
|
26 | 29 | throw new TargetCallException( |
27 | 30 | \sprintf('Invalid action `%s`->`%s`', $controller, $action), |
28 | 31 | TargetCallException::BAD_ACTION, |
@@ -39,7 +42,8 @@ discard block |
||
39 | 42 | */ |
40 | 43 | public static function validateControllerMethod(\ReflectionMethod $method, mixed $controller = null): void |
41 | 44 | { |
42 | - if ($method->isStatic() || !$method->isPublic()) { |
|
45 | + if ($method->isStatic() || !$method->isPublic()) |
|
46 | + { |
|
43 | 47 | throw new TargetCallException( |
44 | 48 | \sprintf( |
45 | 49 | 'Invalid action `%s`->`%s`', |
@@ -50,11 +54,13 @@ discard block |
||
50 | 54 | ); |
51 | 55 | } |
52 | 56 | |
53 | - if ($controller === null) { |
|
57 | + if ($controller === null) |
|
58 | + { |
|
54 | 59 | return; |
55 | 60 | } |
56 | 61 | |
57 | - if (!\is_object($controller) || !$method->getDeclaringClass()->isInstance($controller)) { |
|
62 | + if (!\is_object($controller) || !$method->getDeclaringClass()->isInstance($controller)) |
|
63 | + { |
|
58 | 64 | throw new TargetCallException( |
59 | 65 | \sprintf( |
60 | 66 | 'Invalid controller. Expected instance of `%s`, got `%s`.', |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | private readonly ContainerInterface $container, |
26 | 26 | private readonly FactoryInterface $factory, |
27 | 27 | private readonly ?EventDispatcherInterface $dispatcher = null |
28 | - ) { |
|
28 | + ){ |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | public function getConnection(?string $name = null): QueueInterface |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | // Replaces alias with real pipeline name |
35 | 35 | $name = $this->config->getAliases()[$name] ?? $name; |
36 | 36 | |
37 | - if (!isset($this->pipelines[$name])) { |
|
37 | + if (!isset($this->pipelines[$name])){ |
|
38 | 38 | $this->pipelines[$name] = $this->resolveConnection($name); |
39 | 39 | } |
40 | 40 | |
@@ -49,12 +49,12 @@ discard block |
||
49 | 49 | { |
50 | 50 | $config = $this->config->getConnection($name); |
51 | 51 | |
52 | - try { |
|
52 | + try{ |
|
53 | 53 | $driver = $this->factory->make($config['driver'], $config); |
54 | 54 | $pipeline = (new InterceptorPipeline($this->dispatcher))->withHandler(new PushCore($driver)); |
55 | 55 | |
56 | - foreach ($this->config->getPushInterceptors() as $interceptor) { |
|
57 | - if (\is_string($interceptor) || $interceptor instanceof Autowire) { |
|
56 | + foreach ($this->config->getPushInterceptors() as $interceptor){ |
|
57 | + if (\is_string($interceptor) || $interceptor instanceof Autowire){ |
|
58 | 58 | $interceptor = $this->container->get($interceptor); |
59 | 59 | } |
60 | 60 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | } |
64 | 64 | |
65 | 65 | return new Queue($pipeline); |
66 | - } catch (ContainerException $e) { |
|
66 | + }catch (ContainerException $e){ |
|
67 | 67 | throw new Exception\NotSupportedDriverException( |
68 | 68 | \sprintf( |
69 | 69 | 'Driver `%s` is not supported. Connection `%s` cannot be created. Reason: `%s`', |
@@ -34,7 +34,8 @@ discard block |
||
34 | 34 | // Replaces alias with real pipeline name |
35 | 35 | $name = $this->config->getAliases()[$name] ?? $name; |
36 | 36 | |
37 | - if (!isset($this->pipelines[$name])) { |
|
37 | + if (!isset($this->pipelines[$name])) |
|
38 | + { |
|
38 | 39 | $this->pipelines[$name] = $this->resolveConnection($name); |
39 | 40 | } |
40 | 41 | |
@@ -49,12 +50,15 @@ discard block |
||
49 | 50 | { |
50 | 51 | $config = $this->config->getConnection($name); |
51 | 52 | |
52 | - try { |
|
53 | + try |
|
54 | + { |
|
53 | 55 | $driver = $this->factory->make($config['driver'], $config); |
54 | 56 | $pipeline = (new InterceptorPipeline($this->dispatcher))->withHandler(new PushCore($driver)); |
55 | 57 | |
56 | - foreach ($this->config->getPushInterceptors() as $interceptor) { |
|
57 | - if (\is_string($interceptor) || $interceptor instanceof Autowire) { |
|
58 | + foreach ($this->config->getPushInterceptors() as $interceptor) |
|
59 | + { |
|
60 | + if (\is_string($interceptor) || $interceptor instanceof Autowire) |
|
61 | + { |
|
58 | 62 | $interceptor = $this->container->get($interceptor); |
59 | 63 | } |
60 | 64 | |
@@ -63,7 +67,9 @@ discard block |
||
63 | 67 | } |
64 | 68 | |
65 | 69 | return new Queue($pipeline); |
66 | - } catch (ContainerException $e) { |
|
70 | + } |
|
71 | + catch (ContainerException $e) |
|
72 | + { |
|
67 | 73 | throw new Exception\NotSupportedDriverException( |
68 | 74 | \sprintf( |
69 | 75 | 'Driver `%s` is not supported. Connection `%s` cannot be created. Reason: `%s`', |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | public function __construct( |
57 | 57 | private readonly ConfiguratorInterface $config, |
58 | - ) { |
|
58 | + ){ |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | public function init( |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | $registry = $container->get(QueueRegistry::class); |
74 | 74 | $config = $container->get(QueueConfig::class); |
75 | 75 | |
76 | - foreach ($config->getRegistryHandlers() as $jobType => $handler) { |
|
76 | + foreach ($config->getRegistryHandlers() as $jobType => $handler){ |
|
77 | 77 | $registry->setHandler($jobType, $handler); |
78 | 78 | } |
79 | 79 | |
80 | - foreach ($config->getRegistrySerializers() as $jobType => $serializer) { |
|
80 | + foreach ($config->getRegistrySerializers() as $jobType => $serializer){ |
|
81 | 81 | $registry->setSerializer($jobType, $serializer); |
82 | 82 | } |
83 | 83 | }); |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | /** |
96 | 96 | * @param class-string<CoreInterceptorInterface>|CoreInterceptorInterface|Autowire $interceptor |
97 | 97 | */ |
98 | - public function addConsumeInterceptor(string|CoreInterceptorInterface|Autowire $interceptor): void |
|
98 | + public function addConsumeInterceptor(string | CoreInterceptorInterface | Autowire $interceptor): void |
|
99 | 99 | { |
100 | 100 | $this->config->modify( |
101 | 101 | QueueConfig::CONFIG, |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | /** |
107 | 107 | * @param class-string<CoreInterceptorInterface>|CoreInterceptorInterface|Autowire $interceptor |
108 | 108 | */ |
109 | - public function addPushInterceptor(string|CoreInterceptorInterface|Autowire $interceptor): void |
|
109 | + public function addPushInterceptor(string | CoreInterceptorInterface | Autowire $interceptor): void |
|
110 | 110 | { |
111 | 111 | $this->config->modify( |
112 | 112 | QueueConfig::CONFIG, |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | ContainerInterface $container, |
132 | 132 | FactoryInterface $factory, |
133 | 133 | ContainerRegistry $registry, |
134 | - ) { |
|
134 | + ){ |
|
135 | 135 | return new QueueRegistry($container, $factory, $registry); |
136 | 136 | } |
137 | 137 | |
@@ -145,10 +145,10 @@ discard block |
||
145 | 145 | ): Handler { |
146 | 146 | $pipeline = (new InterceptorPipeline($dispatcher))->withHandler($core); |
147 | 147 | |
148 | - foreach ($config->getConsumeInterceptors() as $interceptor) { |
|
149 | - if (\is_string($interceptor)) { |
|
148 | + foreach ($config->getConsumeInterceptors() as $interceptor){ |
|
149 | + if (\is_string($interceptor)){ |
|
150 | 150 | $interceptor = $container->get($interceptor); |
151 | - } elseif ($interceptor instanceof Autowire) { |
|
151 | + } elseif ($interceptor instanceof Autowire){ |
|
152 | 152 | $interceptor = $interceptor->resolve($factory); |
153 | 153 | } |
154 | 154 |
@@ -73,11 +73,13 @@ discard block |
||
73 | 73 | $registry = $container->get(QueueRegistry::class); |
74 | 74 | $config = $container->get(QueueConfig::class); |
75 | 75 | |
76 | - foreach ($config->getRegistryHandlers() as $jobType => $handler) { |
|
76 | + foreach ($config->getRegistryHandlers() as $jobType => $handler) |
|
77 | + { |
|
77 | 78 | $registry->setHandler($jobType, $handler); |
78 | 79 | } |
79 | 80 | |
80 | - foreach ($config->getRegistrySerializers() as $jobType => $serializer) { |
|
81 | + foreach ($config->getRegistrySerializers() as $jobType => $serializer) |
|
82 | + { |
|
81 | 83 | $registry->setSerializer($jobType, $serializer); |
82 | 84 | } |
83 | 85 | }); |
@@ -145,10 +147,14 @@ discard block |
||
145 | 147 | ): Handler { |
146 | 148 | $pipeline = (new InterceptorPipeline($dispatcher))->withHandler($core); |
147 | 149 | |
148 | - foreach ($config->getConsumeInterceptors() as $interceptor) { |
|
149 | - if (\is_string($interceptor)) { |
|
150 | + foreach ($config->getConsumeInterceptors() as $interceptor) |
|
151 | + { |
|
152 | + if (\is_string($interceptor)) |
|
153 | + { |
|
150 | 154 | $interceptor = $container->get($interceptor); |
151 | - } elseif ($interceptor instanceof Autowire) { |
|
155 | + } |
|
156 | + elseif ($interceptor instanceof Autowire) |
|
157 | + { |
|
152 | 158 | $interceptor = $interceptor->resolve($factory); |
153 | 159 | } |
154 | 160 |
@@ -21,8 +21,8 @@ |
||
21 | 21 | private readonly bool $isLegacy; |
22 | 22 | |
23 | 23 | public function __construct( |
24 | - private readonly CoreInterface|InterceptorHandler $core, |
|
25 | - ) { |
|
24 | + private readonly CoreInterface | InterceptorHandler $core, |
|
25 | + ){ |
|
26 | 26 | $this->isLegacy = !$core instanceof HandlerInterface; |
27 | 27 | } |
28 | 28 |
@@ -96,7 +96,8 @@ |
||
96 | 96 | ): FilterProvider { |
97 | 97 | $pipeline = (new InterceptorPipeline($dispatcher))->withHandler(new Core()); |
98 | 98 | |
99 | - foreach ($config->getInterceptors() as $interceptor) { |
|
99 | + foreach ($config->getInterceptors() as $interceptor) |
|
100 | + { |
|
100 | 101 | $pipeline->addInterceptor($container->get($interceptor)); |
101 | 102 | } |
102 | 103 |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | private readonly ContainerInterface $container, |
44 | 44 | private readonly BinderInterface $binder, |
45 | 45 | private readonly ConfiguratorInterface $config |
46 | - ) { |
|
46 | + ){ |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | public function defineSingletons(): array |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | ): FilterProvider { |
114 | 114 | $pipeline = (new InterceptorPipeline($dispatcher))->withHandler(new Core()); |
115 | 115 | |
116 | - foreach ($config->getInterceptors() as $interceptor) { |
|
116 | + foreach ($config->getInterceptors() as $interceptor){ |
|
117 | 117 | $pipeline->addInterceptor($container->get($interceptor)); |
118 | 118 | } |
119 | 119 |
@@ -72,11 +72,13 @@ discard block |
||
72 | 72 | FinalizerInterface $finalizer, |
73 | 73 | ?EventDispatcherInterface $eventDispatcher = null |
74 | 74 | ): void { |
75 | - if ($eventDispatcher !== null) { |
|
75 | + if ($eventDispatcher !== null) |
|
76 | + { |
|
76 | 77 | $this->initEventDispatcher(new Core($eventDispatcher), $config, $container, $factory); |
77 | 78 | } |
78 | 79 | |
79 | - foreach ($config->getProcessors() as $processor) { |
|
80 | + foreach ($config->getProcessors() as $processor) |
|
81 | + { |
|
80 | 82 | $processor = $this->autowire($processor, $container, $factory); |
81 | 83 | |
82 | 84 | \assert($processor instanceof ProcessorInterface); |
@@ -87,7 +89,8 @@ discard block |
||
87 | 89 | $registry->process(); |
88 | 90 | }); |
89 | 91 | |
90 | - if ($finalizer instanceof EventDispatcherAwareInterface && $eventDispatcher !== null) { |
|
92 | + if ($finalizer instanceof EventDispatcherAwareInterface && $eventDispatcher !== null) |
|
93 | + { |
|
91 | 94 | $finalizer->setEventDispatcher($eventDispatcher); |
92 | 95 | } |
93 | 96 | } |
@@ -108,7 +111,8 @@ discard block |
||
108 | 111 | ): void { |
109 | 112 | $pipeline = (new InterceptorPipeline())->withCore($core); |
110 | 113 | |
111 | - foreach ($config->getInterceptors() as $interceptor) { |
|
114 | + foreach ($config->getInterceptors() as $interceptor) |
|
115 | + { |
|
112 | 116 | $interceptor = $this->autowire($interceptor, $container, $factory); |
113 | 117 | |
114 | 118 | \assert($interceptor instanceof CoreInterceptorInterface || $interceptor instanceof InterceptorInterface); |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | |
49 | 49 | public function __construct( |
50 | 50 | private readonly ConfiguratorInterface $configs |
51 | - ) { |
|
51 | + ){ |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | public function init(): void |
@@ -72,11 +72,11 @@ discard block |
||
72 | 72 | FinalizerInterface $finalizer, |
73 | 73 | ?EventDispatcherInterface $eventDispatcher = null |
74 | 74 | ): void { |
75 | - if ($eventDispatcher !== null) { |
|
75 | + if ($eventDispatcher !== null){ |
|
76 | 76 | $this->initEventDispatcher(new Core($eventDispatcher), $config, $container, $factory); |
77 | 77 | } |
78 | 78 | |
79 | - foreach ($config->getProcessors() as $processor) { |
|
79 | + foreach ($config->getProcessors() as $processor){ |
|
80 | 80 | $processor = $this->autowire($processor, $container, $factory); |
81 | 81 | |
82 | 82 | \assert($processor instanceof ProcessorInterface); |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | $registry->process(); |
88 | 88 | }); |
89 | 89 | |
90 | - if ($finalizer instanceof EventDispatcherAwareInterface && $eventDispatcher !== null) { |
|
90 | + if ($finalizer instanceof EventDispatcherAwareInterface && $eventDispatcher !== null){ |
|
91 | 91 | $finalizer->setEventDispatcher($eventDispatcher); |
92 | 92 | } |
93 | 93 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * @param TInterceptor $interceptor |
97 | 97 | */ |
98 | 98 | public function addInterceptor( |
99 | - string|InterceptorInterface|CoreInterceptorInterface|Container\Autowire $interceptor, |
|
99 | + string | InterceptorInterface | CoreInterceptorInterface | Container\Autowire $interceptor, |
|
100 | 100 | ): void { |
101 | 101 | $this->configs->modify(EventsConfig::CONFIG, new Append('interceptors', null, $interceptor)); |
102 | 102 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | ): void { |
110 | 110 | $pipeline = (new InterceptorPipeline())->withCore($core); |
111 | 111 | |
112 | - foreach ($config->getInterceptors() as $interceptor) { |
|
112 | + foreach ($config->getInterceptors() as $interceptor){ |
|
113 | 113 | $interceptor = $this->autowire($interceptor, $container, $factory); |
114 | 114 | |
115 | 115 | \assert($interceptor instanceof CoreInterceptorInterface || $interceptor instanceof InterceptorInterface); |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @throws ContainerExceptionInterface |
131 | 131 | */ |
132 | - private function autowire(string|object $id, ContainerInterface $container, FactoryInterface $factory): object |
|
132 | + private function autowire(string | object $id, ContainerInterface $container, FactoryInterface $factory): object |
|
133 | 133 | { |
134 | 134 | return match (true) { |
135 | 135 | \is_string($id) => $container->get($id), |
@@ -96,7 +96,8 @@ discard block |
||
96 | 96 | $output = ''; |
97 | 97 | |
98 | 98 | $response = $this->responseFactory->createResponse(200); |
99 | - try { |
|
99 | + try |
|
100 | + { |
|
100 | 101 | $action = $this->verbActions |
101 | 102 | ? \strtolower($request->getMethod()) . \ucfirst($this->action) |
102 | 103 | : $this->action; |
@@ -128,14 +129,21 @@ discard block |
||
128 | 129 | ] |
129 | 130 | ) |
130 | 131 | ); |
131 | - } catch (TargetCallException $e) { |
|
132 | + } |
|
133 | + catch (TargetCallException $e) |
|
134 | + { |
|
132 | 135 | \ob_get_clean(); |
133 | 136 | throw $this->mapException($e); |
134 | - } catch (\Throwable $e) { |
|
137 | + } |
|
138 | + catch (\Throwable $e) |
|
139 | + { |
|
135 | 140 | \ob_get_clean(); |
136 | 141 | throw $e; |
137 | - } finally { |
|
138 | - while (\ob_get_level() > $outputLevel + 1) { |
|
142 | + } |
|
143 | + finally |
|
144 | + { |
|
145 | + while (\ob_get_level() > $outputLevel + 1) |
|
146 | + { |
|
139 | 147 | $output = \ob_get_clean() . $output; |
140 | 148 | } |
141 | 149 | } |
@@ -156,21 +164,27 @@ discard block |
||
156 | 164 | */ |
157 | 165 | private function wrapResponse(Response $response, mixed $result = null, string $output = ''): Response |
158 | 166 | { |
159 | - if ($result instanceof Response) { |
|
160 | - if ($output !== '' && $result->getBody()->isWritable()) { |
|
167 | + if ($result instanceof Response) |
|
168 | + { |
|
169 | + if ($output !== '' && $result->getBody()->isWritable()) |
|
170 | + { |
|
161 | 171 | $result->getBody()->write($output); |
162 | 172 | } |
163 | 173 | |
164 | 174 | return $result; |
165 | 175 | } |
166 | 176 | |
167 | - if ($result instanceof \Generator) { |
|
177 | + if ($result instanceof \Generator) |
|
178 | + { |
|
168 | 179 | return $response->withBody(new GeneratorStream($result)); |
169 | 180 | } |
170 | 181 | |
171 | - if (\is_array($result) || $result instanceof \JsonSerializable) { |
|
182 | + if (\is_array($result) || $result instanceof \JsonSerializable) |
|
183 | + { |
|
172 | 184 | $response = $this->writeJson($response, $result); |
173 | - } else { |
|
185 | + } |
|
186 | + else |
|
187 | + { |
|
174 | 188 | $response->getBody()->write((string)$result); |
175 | 189 | } |
176 | 190 | |
@@ -203,7 +217,8 @@ discard block |
||
203 | 217 | */ |
204 | 218 | private function checkValues(): void |
205 | 219 | { |
206 | - if ($this->controller === null) { |
|
220 | + if ($this->controller === null) |
|
221 | + { |
|
207 | 222 | throw new HandlerException('Controller and action pair are not set.'); |
208 | 223 | } |
209 | 224 | } |
@@ -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 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | private ?string $group = null; |
23 | 23 | private ?array $methods = null; |
24 | 24 | private string $prefix = ''; |
25 | - private HandlerInterface|CoreInterface|null $core = null; |
|
25 | + private HandlerInterface | CoreInterface | null $core = null; |
|
26 | 26 | private ?array $middleware = null; |
27 | 27 | |
28 | 28 | /** @var null|string|callable|RequestHandlerInterface|TargetInterface */ |
@@ -36,12 +36,12 @@ discard block |
||
36 | 36 | private readonly string $name, |
37 | 37 | private readonly string $pattern, |
38 | 38 | private readonly RouteCollection $collection |
39 | - ) { |
|
39 | + ){ |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | public function __destruct() |
43 | 43 | { |
44 | - if ($this->target === null) { |
|
44 | + if ($this->target === null){ |
|
45 | 45 | throw new TargetException( |
46 | 46 | \sprintf('The [%s] route has no defined target. Call one of: `controller`, `action`, |
47 | 47 | `namespaced`, `groupControllers`, `callable`, `handler` methods.', $this->name) |
@@ -92,21 +92,21 @@ discard block |
||
92 | 92 | return $this; |
93 | 93 | } |
94 | 94 | |
95 | - public function action(string $controller, string|array $action, int $options = 0): self |
|
95 | + public function action(string $controller, string | array $action, int $options = 0): self |
|
96 | 96 | { |
97 | 97 | $this->target = new Action($controller, $action, $options); |
98 | 98 | |
99 | 99 | return $this; |
100 | 100 | } |
101 | 101 | |
102 | - public function callable(array|\Closure $callable): self |
|
102 | + public function callable(array | \Closure $callable): self |
|
103 | 103 | { |
104 | 104 | $this->target = $callable; |
105 | 105 | |
106 | 106 | return $this; |
107 | 107 | } |
108 | 108 | |
109 | - public function handler(TargetInterface|string $target): self |
|
109 | + public function handler(TargetInterface | string $target): self |
|
110 | 110 | { |
111 | 111 | $this->target = $target; |
112 | 112 | |
@@ -134,16 +134,16 @@ discard block |
||
134 | 134 | return $this; |
135 | 135 | } |
136 | 136 | |
137 | - public function core(HandlerInterface|CoreInterface $core): self |
|
137 | + public function core(HandlerInterface | CoreInterface $core): self |
|
138 | 138 | { |
139 | 139 | $this->core = $core; |
140 | 140 | |
141 | 141 | return $this; |
142 | 142 | } |
143 | 143 | |
144 | - public function middleware(MiddlewareInterface|string|array $middleware): self |
|
144 | + public function middleware(MiddlewareInterface | string | array $middleware): self |
|
145 | 145 | { |
146 | - if (!\is_array($middleware)) { |
|
146 | + if (!\is_array($middleware)){ |
|
147 | 147 | $middleware = [$middleware]; |
148 | 148 | } |
149 | 149 | |
@@ -152,9 +152,9 @@ discard block |
||
152 | 152 | return $this; |
153 | 153 | } |
154 | 154 | |
155 | - public function methods(string|array $methods): self |
|
155 | + public function methods(string | array $methods): self |
|
156 | 156 | { |
157 | - $this->methods = (array) $methods; |
|
157 | + $this->methods = (array)$methods; |
|
158 | 158 | |
159 | 159 | return $this; |
160 | 160 | } |