@@ -7,4 +7,4 @@ |
||
7 | 7 | /** |
8 | 8 | * Exceptions in input manager. |
9 | 9 | */ |
10 | -class InputException extends HttpException {} |
|
10 | +class InputException extends HttpException{} |
@@ -7,4 +7,6 @@ |
||
7 | 7 | /** |
8 | 8 | * Exceptions in input manager. |
9 | 9 | */ |
10 | -class InputException extends HttpException {} |
|
10 | +class InputException extends HttpException |
|
11 | +{ |
|
12 | +} |
@@ -4,4 +4,4 @@ |
||
4 | 4 | |
5 | 5 | namespace Spiral\Http\Exception; |
6 | 6 | |
7 | -class PipelineException extends HttpException {} |
|
7 | +class PipelineException extends HttpException{} |
@@ -4,4 +4,6 @@ |
||
4 | 4 | |
5 | 5 | namespace Spiral\Http\Exception; |
6 | 6 | |
7 | -class PipelineException extends HttpException {} |
|
7 | +class PipelineException extends HttpException |
|
8 | +{ |
|
9 | +} |
@@ -7,4 +7,4 @@ |
||
7 | 7 | /** |
8 | 8 | * Raised when element can not be found using dot notation. |
9 | 9 | */ |
10 | -class DotNotFoundException extends \RuntimeException {} |
|
10 | +class DotNotFoundException extends \RuntimeException{} |
@@ -7,4 +7,4 @@ |
||
7 | 7 | /** |
8 | 8 | * Responder exceptions such as unability to generate response. |
9 | 9 | */ |
10 | -class ResponseException extends HttpException {} |
|
10 | +class ResponseException extends HttpException{} |
@@ -7,4 +7,6 @@ |
||
7 | 7 | /** |
8 | 8 | * Responder exceptions such as unability to generate response. |
9 | 9 | */ |
10 | -class ResponseException extends HttpException {} |
|
10 | +class ResponseException extends HttpException |
|
11 | +{ |
|
12 | +} |
@@ -4,4 +4,4 @@ |
||
4 | 4 | |
5 | 5 | namespace Spiral\Http\Exception; |
6 | 6 | |
7 | -class HttpException extends \RuntimeException {} |
|
7 | +class HttpException extends \RuntimeException{} |
@@ -18,8 +18,8 @@ discard block |
||
18 | 18 | { |
19 | 19 | public function __construct( |
20 | 20 | private readonly array $data, |
21 | - private readonly int|string $prefix = '', |
|
22 | - ) {} |
|
21 | + private readonly int | string $prefix = '', |
|
22 | + ){} |
|
23 | 23 | |
24 | 24 | public function count(): int |
25 | 25 | { |
@@ -28,9 +28,9 @@ discard block |
||
28 | 28 | |
29 | 29 | public function all(): array |
30 | 30 | { |
31 | - try { |
|
31 | + try{ |
|
32 | 32 | return $this->dotGet(''); |
33 | - } catch (DotNotFoundException) { |
|
33 | + }catch (DotNotFoundException){ |
|
34 | 34 | return []; |
35 | 35 | } |
36 | 36 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | public function fetch(array $keys, bool $fill = false, mixed $filler = null): array |
50 | 50 | { |
51 | 51 | $result = \array_intersect_key($this->all(), \array_flip($keys)); |
52 | - if (!$fill) { |
|
52 | + if (!$fill){ |
|
53 | 53 | return $result; |
54 | 54 | } |
55 | 55 | |
@@ -59,11 +59,11 @@ discard block |
||
59 | 59 | /** |
60 | 60 | * Check if field presented (can be empty) by it's name. Dot notation allowed. |
61 | 61 | */ |
62 | - public function has(int|string $name): bool |
|
62 | + public function has(int | string $name): bool |
|
63 | 63 | { |
64 | - try { |
|
64 | + try{ |
|
65 | 65 | $this->dotGet($name); |
66 | - } catch (DotNotFoundException) { |
|
66 | + }catch (DotNotFoundException){ |
|
67 | 67 | return false; |
68 | 68 | } |
69 | 69 | |
@@ -72,9 +72,9 @@ discard block |
||
72 | 72 | |
73 | 73 | public function offsetExists(mixed $offset): bool |
74 | 74 | { |
75 | - try { |
|
75 | + try{ |
|
76 | 76 | return !\is_null($this->dotGet($offset)); |
77 | - } catch (DotNotFoundException) { |
|
77 | + }catch (DotNotFoundException){ |
|
78 | 78 | return false; |
79 | 79 | } |
80 | 80 | } |
@@ -87,11 +87,11 @@ discard block |
||
87 | 87 | /** |
88 | 88 | * Get property or return default value. Dot notation allowed. |
89 | 89 | */ |
90 | - public function get(int|string $name, mixed $default = null): mixed |
|
90 | + public function get(int | string $name, mixed $default = null): mixed |
|
91 | 91 | { |
92 | - try { |
|
92 | + try{ |
|
93 | 93 | return $this->dotGet($name); |
94 | - } catch (DotNotFoundException) { |
|
94 | + }catch (DotNotFoundException){ |
|
95 | 95 | return $default; |
96 | 96 | } |
97 | 97 | } |
@@ -122,20 +122,20 @@ discard block |
||
122 | 122 | * |
123 | 123 | * @throws DotNotFoundException |
124 | 124 | */ |
125 | - private function dotGet(int|string $name): mixed |
|
125 | + private function dotGet(int | string $name): mixed |
|
126 | 126 | { |
127 | 127 | $data = $this->data; |
128 | 128 | |
129 | 129 | //Generating path relative to a given name and prefix |
130 | - $path = (empty($this->prefix) ? '' : $this->prefix . '.') . $name; |
|
131 | - if (empty($path)) { |
|
130 | + $path = (empty($this->prefix) ? '' : $this->prefix.'.').$name; |
|
131 | + if (empty($path)){ |
|
132 | 132 | return $data; |
133 | 133 | } |
134 | 134 | |
135 | 135 | $path = \explode('.', \rtrim($path, '.')); |
136 | 136 | |
137 | - foreach ($path as $step) { |
|
138 | - if (!\is_array($data) || !\array_key_exists($step, $data)) { |
|
137 | + foreach ($path as $step){ |
|
138 | + if (!\is_array($data) || !\array_key_exists($step, $data)){ |
|
139 | 139 | throw new DotNotFoundException(\sprintf("Unable to find requested element '%s'.", $name)); |
140 | 140 | } |
141 | 141 |
@@ -19,7 +19,8 @@ discard block |
||
19 | 19 | public function __construct( |
20 | 20 | private readonly array $data, |
21 | 21 | private readonly int|string $prefix = '', |
22 | - ) {} |
|
22 | + ) { |
|
23 | +} |
|
23 | 24 | |
24 | 25 | public function count(): int |
25 | 26 | { |
@@ -28,9 +29,12 @@ discard block |
||
28 | 29 | |
29 | 30 | public function all(): array |
30 | 31 | { |
31 | - try { |
|
32 | + try |
|
33 | + { |
|
32 | 34 | return $this->dotGet(''); |
33 | - } catch (DotNotFoundException) { |
|
35 | + } |
|
36 | + catch (DotNotFoundException) |
|
37 | + { |
|
34 | 38 | return []; |
35 | 39 | } |
36 | 40 | } |
@@ -49,7 +53,8 @@ discard block |
||
49 | 53 | public function fetch(array $keys, bool $fill = false, mixed $filler = null): array |
50 | 54 | { |
51 | 55 | $result = \array_intersect_key($this->all(), \array_flip($keys)); |
52 | - if (!$fill) { |
|
56 | + if (!$fill) |
|
57 | + { |
|
53 | 58 | return $result; |
54 | 59 | } |
55 | 60 | |
@@ -61,9 +66,12 @@ discard block |
||
61 | 66 | */ |
62 | 67 | public function has(int|string $name): bool |
63 | 68 | { |
64 | - try { |
|
69 | + try |
|
70 | + { |
|
65 | 71 | $this->dotGet($name); |
66 | - } catch (DotNotFoundException) { |
|
72 | + } |
|
73 | + catch (DotNotFoundException) |
|
74 | + { |
|
67 | 75 | return false; |
68 | 76 | } |
69 | 77 | |
@@ -72,9 +80,12 @@ discard block |
||
72 | 80 | |
73 | 81 | public function offsetExists(mixed $offset): bool |
74 | 82 | { |
75 | - try { |
|
83 | + try |
|
84 | + { |
|
76 | 85 | return !\is_null($this->dotGet($offset)); |
77 | - } catch (DotNotFoundException) { |
|
86 | + } |
|
87 | + catch (DotNotFoundException) |
|
88 | + { |
|
78 | 89 | return false; |
79 | 90 | } |
80 | 91 | } |
@@ -89,9 +100,12 @@ discard block |
||
89 | 100 | */ |
90 | 101 | public function get(int|string $name, mixed $default = null): mixed |
91 | 102 | { |
92 | - try { |
|
103 | + try |
|
104 | + { |
|
93 | 105 | return $this->dotGet($name); |
94 | - } catch (DotNotFoundException) { |
|
106 | + } |
|
107 | + catch (DotNotFoundException) |
|
108 | + { |
|
95 | 109 | return $default; |
96 | 110 | } |
97 | 111 | } |
@@ -128,14 +142,17 @@ discard block |
||
128 | 142 | |
129 | 143 | //Generating path relative to a given name and prefix |
130 | 144 | $path = (empty($this->prefix) ? '' : $this->prefix . '.') . $name; |
131 | - if (empty($path)) { |
|
145 | + if (empty($path)) |
|
146 | + { |
|
132 | 147 | return $data; |
133 | 148 | } |
134 | 149 | |
135 | 150 | $path = \explode('.', \rtrim($path, '.')); |
136 | 151 | |
137 | - foreach ($path as $step) { |
|
138 | - if (!\is_array($data) || !\array_key_exists($step, $data)) { |
|
152 | + foreach ($path as $step) |
|
153 | + { |
|
154 | + if (!\is_array($data) || !\array_key_exists($step, $data)) |
|
155 | + { |
|
139 | 156 | throw new DotNotFoundException(\sprintf("Unable to find requested element '%s'.", $name)); |
140 | 157 | } |
141 | 158 |
@@ -25,21 +25,21 @@ discard block |
||
25 | 25 | { |
26 | 26 | private ?RequestHandlerInterface $handler = null; |
27 | 27 | private readonly TracerFactoryInterface $tracerFactory; |
28 | - private readonly Pipeline|LazyPipeline $pipeline; |
|
28 | + private readonly Pipeline | LazyPipeline $pipeline; |
|
29 | 29 | |
30 | 30 | public function __construct( |
31 | 31 | private readonly HttpConfig $config, |
32 | - Pipeline|LazyPipeline $pipeline, |
|
32 | + Pipeline | LazyPipeline $pipeline, |
|
33 | 33 | private readonly ResponseFactoryInterface $responseFactory, |
34 | 34 | private readonly ContainerInterface $container, |
35 | 35 | ?TracerFactoryInterface $tracerFactory = null, |
36 | 36 | private readonly ?EventDispatcherInterface $dispatcher = null, |
37 | - ) { |
|
38 | - if ($pipeline instanceof Pipeline) { |
|
39 | - foreach ($this->config->getMiddleware() as $middleware) { |
|
37 | + ){ |
|
38 | + if ($pipeline instanceof Pipeline){ |
|
39 | + foreach ($this->config->getMiddleware() as $middleware){ |
|
40 | 40 | $pipeline->pushMiddleware($this->container->get($middleware)); |
41 | 41 | } |
42 | - } else { |
|
42 | + }else{ |
|
43 | 43 | $pipeline = $pipeline->withAddedMiddleware( |
44 | 44 | ...$this->config->getMiddleware(), |
45 | 45 | ); |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | /** |
54 | 54 | * @internal |
55 | 55 | */ |
56 | - public function getPipeline(): Pipeline|LazyPipeline |
|
56 | + public function getPipeline(): Pipeline | LazyPipeline |
|
57 | 57 | { |
58 | 58 | return $this->pipeline; |
59 | 59 | } |
60 | 60 | |
61 | - public function setHandler(callable|RequestHandlerInterface $handler): self |
|
61 | + public function setHandler(callable | RequestHandlerInterface $handler): self |
|
62 | 62 | { |
63 | 63 | $this->handler = $handler instanceof RequestHandlerInterface |
64 | 64 | ? $handler |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | |
78 | 78 | $this->dispatcher?->dispatch(new RequestReceived($request)); |
79 | 79 | |
80 | - if ($this->handler === null) { |
|
80 | + if ($this->handler === null){ |
|
81 | 81 | throw new HttpException('Unable to run HttpCore, no handler is set.'); |
82 | 82 | } |
83 | 83 | |
@@ -103,11 +103,11 @@ discard block |
||
103 | 103 | |
104 | 104 | /** @var ResponseInterface $response */ |
105 | 105 | $response = $tracer->trace( |
106 | - name: \sprintf('%s %s', $request->getMethod(), (string) $request->getUri()), |
|
106 | + name: \sprintf('%s %s', $request->getMethod(), (string)$request->getUri()), |
|
107 | 107 | callback: $callback, |
108 | 108 | attributes: [ |
109 | 109 | 'http.method' => $request->getMethod(), |
110 | - 'http.url' => (string) $request->getUri(), |
|
110 | + 'http.url' => (string)$request->getUri(), |
|
111 | 111 | 'http.headers' => \array_map( |
112 | 112 | static fn(array $values): string => \implode(',', $values), |
113 | 113 | $request->getHeaders(), |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | traceKind: TraceKind::SERVER, |
118 | 118 | ); |
119 | 119 | |
120 | - foreach ($tracer->getContext() as $key => $value) { |
|
120 | + foreach ($tracer->getContext() as $key => $value){ |
|
121 | 121 | $response = $response->withHeader($key, $value); |
122 | 122 | } |
123 | 123 |
@@ -35,11 +35,15 @@ discard block |
||
35 | 35 | ?TracerFactoryInterface $tracerFactory = null, |
36 | 36 | private readonly ?EventDispatcherInterface $dispatcher = null, |
37 | 37 | ) { |
38 | - if ($pipeline instanceof Pipeline) { |
|
39 | - foreach ($this->config->getMiddleware() as $middleware) { |
|
38 | + if ($pipeline instanceof Pipeline) |
|
39 | + { |
|
40 | + foreach ($this->config->getMiddleware() as $middleware) |
|
41 | + { |
|
40 | 42 | $pipeline->pushMiddleware($this->container->get($middleware)); |
41 | 43 | } |
42 | - } else { |
|
44 | + } |
|
45 | + else |
|
46 | + { |
|
43 | 47 | $pipeline = $pipeline->withAddedMiddleware( |
44 | 48 | ...$this->config->getMiddleware(), |
45 | 49 | ); |
@@ -77,7 +81,8 @@ discard block |
||
77 | 81 | |
78 | 82 | $this->dispatcher?->dispatch(new RequestReceived($request)); |
79 | 83 | |
80 | - if ($this->handler === null) { |
|
84 | + if ($this->handler === null) |
|
85 | + { |
|
81 | 86 | throw new HttpException('Unable to run HttpCore, no handler is set.'); |
82 | 87 | } |
83 | 88 | |
@@ -117,7 +122,8 @@ discard block |
||
117 | 122 | traceKind: TraceKind::SERVER, |
118 | 123 | ); |
119 | 124 | |
120 | - foreach ($tracer->getContext() as $key => $value) { |
|
125 | + foreach ($tracer->getContext() as $key => $value) |
|
126 | + { |
|
121 | 127 | $response = $response->withHeader($key, $value); |
122 | 128 | } |
123 | 129 |
@@ -4,4 +4,4 @@ |
||
4 | 4 | |
5 | 5 | namespace Spiral\Tests\Scaffolder\App\Controller; |
6 | 6 | |
7 | -class DefaultController {} |
|
7 | +class DefaultController{} |
@@ -4,4 +4,6 @@ |
||
4 | 4 | |
5 | 5 | namespace Spiral\Tests\Scaffolder\App\Controller; |
6 | 6 | |
7 | -class DefaultController {} |
|
7 | +class DefaultController |
|
8 | +{ |
|
9 | +} |
@@ -11,7 +11,7 @@ |
||
11 | 11 | final class CommandWithoutNamespace extends AbstractCommand |
12 | 12 | { |
13 | 13 | protected const NAME = 'create:command-without-namespace'; |
14 | - protected const ARGUMENTS = [ |
|
14 | + protected const ARGUMENTS = [ |
|
15 | 15 | ['name', InputArgument::REQUIRED, 'Command name'], |
16 | 16 | ['alias', InputArgument::OPTIONAL, 'Command id/alias'], |
17 | 17 | ]; |