@@ -45,17 +45,17 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function __toString(): string |
47 | 47 | { |
48 | - if ($this->value === '') { |
|
48 | + if ($this->value === ''){ |
|
49 | 49 | return ''; |
50 | 50 | } |
51 | 51 | |
52 | 52 | $parts = [$this->value]; |
53 | 53 | |
54 | - if ($this->quality < 1) { |
|
54 | + if ($this->quality < 1){ |
|
55 | 55 | $parts[] = "q=$this->quality"; |
56 | 56 | } |
57 | 57 | |
58 | - foreach ($this->getParams() as $name => $value) { |
|
58 | + foreach ($this->getParams() as $name => $value){ |
|
59 | 59 | $parts[] = "$name=$value"; |
60 | 60 | } |
61 | 61 | |
@@ -76,20 +76,20 @@ discard block |
||
76 | 76 | $quality = 1.0; |
77 | 77 | $params = []; |
78 | 78 | |
79 | - foreach ($elements as $element) { |
|
79 | + foreach ($elements as $element){ |
|
80 | 80 | $parsed = explode('=', trim($element), 2); |
81 | 81 | |
82 | 82 | // Wrong params must be ignored |
83 | - if (count($parsed) !== 2) { |
|
83 | + if (count($parsed) !== 2){ |
|
84 | 84 | continue; |
85 | 85 | } |
86 | 86 | |
87 | 87 | $name = trim($parsed[0]); |
88 | 88 | $value = trim($parsed[1]); |
89 | 89 | |
90 | - if (strcasecmp($name, 'q') === 0) { |
|
90 | + if (strcasecmp($name, 'q') === 0){ |
|
91 | 91 | $quality = (float)$value; |
92 | - } else { |
|
92 | + }else{ |
|
93 | 93 | $params[$name] = $value; |
94 | 94 | } |
95 | 95 | } |
@@ -178,15 +178,15 @@ discard block |
||
178 | 178 | */ |
179 | 179 | private function setParams(array $params): void |
180 | 180 | { |
181 | - foreach ($params as $name => $value) { |
|
182 | - if (is_numeric($name) || !is_scalar($value)) { |
|
181 | + foreach ($params as $name => $value){ |
|
182 | + if (is_numeric($name) || !is_scalar($value)){ |
|
183 | 183 | continue; |
184 | 184 | } |
185 | 185 | |
186 | 186 | $name = trim($name); |
187 | 187 | $value = trim($value); |
188 | 188 | |
189 | - if ($name === '' || $value === '') { |
|
189 | + if ($name === '' || $value === ''){ |
|
190 | 190 | continue; |
191 | 191 | } |
192 | 192 |
@@ -45,17 +45,20 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function __toString(): string |
47 | 47 | { |
48 | - if ($this->value === '') { |
|
48 | + if ($this->value === '') |
|
49 | + { |
|
49 | 50 | return ''; |
50 | 51 | } |
51 | 52 | |
52 | 53 | $parts = [$this->value]; |
53 | 54 | |
54 | - if ($this->quality < 1) { |
|
55 | + if ($this->quality < 1) |
|
56 | + { |
|
55 | 57 | $parts[] = "q=$this->quality"; |
56 | 58 | } |
57 | 59 | |
58 | - foreach ($this->getParams() as $name => $value) { |
|
60 | + foreach ($this->getParams() as $name => $value) |
|
61 | + { |
|
59 | 62 | $parts[] = "$name=$value"; |
60 | 63 | } |
61 | 64 | |
@@ -76,20 +79,25 @@ discard block |
||
76 | 79 | $quality = 1.0; |
77 | 80 | $params = []; |
78 | 81 | |
79 | - foreach ($elements as $element) { |
|
82 | + foreach ($elements as $element) |
|
83 | + { |
|
80 | 84 | $parsed = explode('=', trim($element), 2); |
81 | 85 | |
82 | 86 | // Wrong params must be ignored |
83 | - if (count($parsed) !== 2) { |
|
87 | + if (count($parsed) !== 2) |
|
88 | + { |
|
84 | 89 | continue; |
85 | 90 | } |
86 | 91 | |
87 | 92 | $name = trim($parsed[0]); |
88 | 93 | $value = trim($parsed[1]); |
89 | 94 | |
90 | - if (strcasecmp($name, 'q') === 0) { |
|
95 | + if (strcasecmp($name, 'q') === 0) |
|
96 | + { |
|
91 | 97 | $quality = (float)$value; |
92 | - } else { |
|
98 | + } |
|
99 | + else |
|
100 | + { |
|
93 | 101 | $params[$name] = $value; |
94 | 102 | } |
95 | 103 | } |
@@ -178,15 +186,18 @@ discard block |
||
178 | 186 | */ |
179 | 187 | private function setParams(array $params): void |
180 | 188 | { |
181 | - foreach ($params as $name => $value) { |
|
182 | - if (is_numeric($name) || !is_scalar($value)) { |
|
189 | + foreach ($params as $name => $value) |
|
190 | + { |
|
191 | + if (is_numeric($name) || !is_scalar($value)) |
|
192 | + { |
|
183 | 193 | continue; |
184 | 194 | } |
185 | 195 | |
186 | 196 | $name = trim($name); |
187 | 197 | $value = trim($value); |
188 | 198 | |
189 | - if ($name === '' || $value === '') { |
|
199 | + if ($name === '' || $value === '') |
|
200 | + { |
|
190 | 201 | continue; |
191 | 202 | } |
192 | 203 |
@@ -29,11 +29,11 @@ |
||
29 | 29 | */ |
30 | 30 | private function writeJson(ResponseInterface $response, $payload, int $code = 200): ResponseInterface |
31 | 31 | { |
32 | - if ($payload instanceof JsonSerializable) { |
|
32 | + if ($payload instanceof JsonSerializable){ |
|
33 | 33 | $payload = $payload->jsonSerialize(); |
34 | 34 | } |
35 | 35 | |
36 | - if (is_array($payload) && isset($payload['status'])) { |
|
36 | + if (is_array($payload) && isset($payload['status'])){ |
|
37 | 37 | $code = $payload['status']; |
38 | 38 | } |
39 | 39 |
@@ -29,11 +29,13 @@ |
||
29 | 29 | */ |
30 | 30 | private function writeJson(ResponseInterface $response, $payload, int $code = 200): ResponseInterface |
31 | 31 | { |
32 | - if ($payload instanceof JsonSerializable) { |
|
32 | + if ($payload instanceof JsonSerializable) |
|
33 | + { |
|
33 | 34 | $payload = $payload->jsonSerialize(); |
34 | 35 | } |
35 | 36 | |
36 | - if (is_array($payload) && isset($payload['status'])) { |
|
37 | + if (is_array($payload) && isset($payload['status'])) |
|
38 | + { |
|
37 | 39 | $code = $payload['status']; |
38 | 40 | } |
39 | 41 |
@@ -67,11 +67,11 @@ discard block |
||
67 | 67 | */ |
68 | 68 | private function assertNoPreviousOutput(): void |
69 | 69 | { |
70 | - if (headers_sent()) { |
|
70 | + if (headers_sent()){ |
|
71 | 71 | throw new EmitterException('Unable to emit response, headers already send.'); |
72 | 72 | } |
73 | 73 | |
74 | - if (ob_get_level() > 0 && ob_get_length() > 0) { |
|
74 | + if (ob_get_level() > 0 && ob_get_length() > 0){ |
|
75 | 75 | throw new EmitterException('Unable to emit response, found non closed buffered output.'); |
76 | 76 | } |
77 | 77 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | 'HTTP/%s %d%s', |
98 | 98 | $response->getProtocolVersion(), |
99 | 99 | $statusCode, |
100 | - ($reasonPhrase ? ' ' . $reasonPhrase : '') |
|
100 | + ($reasonPhrase ? ' '.$reasonPhrase : '') |
|
101 | 101 | ), true, $statusCode); |
102 | 102 | } |
103 | 103 | |
@@ -115,10 +115,10 @@ discard block |
||
115 | 115 | { |
116 | 116 | $statusCode = $response->getStatusCode(); |
117 | 117 | |
118 | - foreach ($response->getHeaders() as $header => $values) { |
|
118 | + foreach ($response->getHeaders() as $header => $values){ |
|
119 | 119 | $name = $this->filterHeader($header); |
120 | 120 | $first = $name === 'Set-Cookie' ? false : true; |
121 | - foreach ($values as $value) { |
|
121 | + foreach ($values as $value){ |
|
122 | 122 | header(sprintf( |
123 | 123 | '%s: %s', |
124 | 124 | $name, |
@@ -67,11 +67,13 @@ discard block |
||
67 | 67 | */ |
68 | 68 | private function assertNoPreviousOutput(): void |
69 | 69 | { |
70 | - if (headers_sent()) { |
|
70 | + if (headers_sent()) |
|
71 | + { |
|
71 | 72 | throw new EmitterException('Unable to emit response, headers already send.'); |
72 | 73 | } |
73 | 74 | |
74 | - if (ob_get_level() > 0 && ob_get_length() > 0) { |
|
75 | + if (ob_get_level() > 0 && ob_get_length() > 0) |
|
76 | + { |
|
75 | 77 | throw new EmitterException('Unable to emit response, found non closed buffered output.'); |
76 | 78 | } |
77 | 79 | } |
@@ -115,10 +117,12 @@ discard block |
||
115 | 117 | { |
116 | 118 | $statusCode = $response->getStatusCode(); |
117 | 119 | |
118 | - foreach ($response->getHeaders() as $header => $values) { |
|
120 | + foreach ($response->getHeaders() as $header => $values) |
|
121 | + { |
|
119 | 122 | $name = $this->filterHeader($header); |
120 | 123 | $first = $name === 'Set-Cookie' ? false : true; |
121 | - foreach ($values as $value) { |
|
124 | + foreach ($values as $value) |
|
125 | + { |
|
122 | 126 | header(sprintf( |
123 | 127 | '%s: %s', |
124 | 128 | $name, |
@@ -73,12 +73,12 @@ |
||
73 | 73 | */ |
74 | 74 | public function handle(Request $request): Response |
75 | 75 | { |
76 | - if (empty($this->handler)) { |
|
76 | + if (empty($this->handler)){ |
|
77 | 77 | throw new PipelineException('Unable to run pipeline, no handler given.'); |
78 | 78 | } |
79 | 79 | |
80 | 80 | $position = $this->position++; |
81 | - if (isset($this->middleware[$position])) { |
|
81 | + if (isset($this->middleware[$position])){ |
|
82 | 82 | return $this->middleware[$position]->process($request, $this); |
83 | 83 | } |
84 | 84 |
@@ -73,16 +73,19 @@ |
||
73 | 73 | */ |
74 | 74 | public function handle(Request $request): Response |
75 | 75 | { |
76 | - if (empty($this->handler)) { |
|
76 | + if (empty($this->handler)) |
|
77 | + { |
|
77 | 78 | throw new PipelineException('Unable to run pipeline, no handler given.'); |
78 | 79 | } |
79 | 80 | |
80 | 81 | $position = $this->position++; |
81 | - if (isset($this->middleware[$position])) { |
|
82 | + if (isset($this->middleware[$position])) |
|
83 | + { |
|
82 | 84 | return $this->middleware[$position]->process($request, $this); |
83 | 85 | } |
84 | 86 | |
85 | - return $this->scope->runScope([Request::class => $request], function () use ($request) { |
|
87 | + return $this->scope->runScope([Request::class => $request], function () use ($request) |
|
88 | + { |
|
86 | 89 | return $this->handler->handle($request); |
87 | 90 | }); |
88 | 91 | } |
@@ -34,11 +34,11 @@ |
||
34 | 34 | */ |
35 | 35 | public function __construct(?int $code = null, string $message = '', ?\Throwable $previous = null) |
36 | 36 | { |
37 | - if (empty($code) && empty($this->code)) { |
|
37 | + if (empty($code) && empty($this->code)){ |
|
38 | 38 | $code = self::BAD_DATA; |
39 | 39 | } |
40 | 40 | |
41 | - if (empty($message)) { |
|
41 | + if (empty($message)){ |
|
42 | 42 | $message = "Http Error - {$code}"; |
43 | 43 | } |
44 | 44 |
@@ -34,11 +34,13 @@ |
||
34 | 34 | */ |
35 | 35 | public function __construct(?int $code = null, string $message = '', ?\Throwable $previous = null) |
36 | 36 | { |
37 | - if (empty($code) && empty($this->code)) { |
|
37 | + if (empty($code) && empty($this->code)) |
|
38 | + { |
|
38 | 39 | $code = self::BAD_DATA; |
39 | 40 | } |
40 | 41 | |
41 | - if (empty($message)) { |
|
42 | + if (empty($message)) |
|
43 | + { |
|
42 | 44 | $message = "Http Error - {$code}"; |
43 | 45 | } |
44 | 46 |
@@ -32,7 +32,7 @@ |
||
32 | 32 | */ |
33 | 33 | public function getFilename(string $name): ?string |
34 | 34 | { |
35 | - if (!empty($file = $this->get($name)) && !$file->getError()) { |
|
35 | + if (!empty($file = $this->get($name)) && !$file->getError()){ |
|
36 | 36 | return StreamWrapper::getFilename($file->getStream()); |
37 | 37 | } |
38 | 38 |
@@ -32,7 +32,8 @@ |
||
32 | 32 | */ |
33 | 33 | public function getFilename(string $name): ?string |
34 | 34 | { |
35 | - if (!empty($file = $this->get($name)) && !$file->getError()) { |
|
35 | + if (!empty($file = $this->get($name)) && !$file->getError()) |
|
36 | + { |
|
36 | 37 | return StreamWrapper::getFilename($file->getStream()); |
37 | 38 | } |
38 | 39 |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function all(): array |
59 | 59 | { |
60 | - try { |
|
60 | + try{ |
|
61 | 61 | return $this->dotGet(''); |
62 | - } catch (DotNotFoundException $e) { |
|
62 | + }catch (DotNotFoundException $e){ |
|
63 | 63 | return []; |
64 | 64 | } |
65 | 65 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | { |
86 | 86 | $result = array_intersect_key($this->all(), array_flip($keys)); |
87 | 87 | ; |
88 | - if (!$fill) { |
|
88 | + if (!$fill){ |
|
89 | 89 | return $result; |
90 | 90 | } |
91 | 91 | |
@@ -108,9 +108,9 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function has(string $name): bool |
110 | 110 | { |
111 | - try { |
|
111 | + try{ |
|
112 | 112 | $this->dotGet($name); |
113 | - } catch (DotNotFoundException $e) { |
|
113 | + }catch (DotNotFoundException $e){ |
|
114 | 114 | return false; |
115 | 115 | } |
116 | 116 | |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | */ |
135 | 135 | public function get(string $name, $default = null) |
136 | 136 | { |
137 | - try { |
|
137 | + try{ |
|
138 | 138 | return $this->dotGet($name); |
139 | - } catch (DotNotFoundException $e) { |
|
139 | + }catch (DotNotFoundException $e){ |
|
140 | 140 | return $default; |
141 | 141 | } |
142 | 142 | } |
@@ -174,15 +174,15 @@ discard block |
||
174 | 174 | $data = $this->data; |
175 | 175 | |
176 | 176 | //Generating path relative to a given name and prefix |
177 | - $path = (!empty($this->prefix) ? $this->prefix . '.' : '') . $name; |
|
178 | - if (empty($path)) { |
|
177 | + $path = (!empty($this->prefix) ? $this->prefix.'.' : '').$name; |
|
178 | + if (empty($path)){ |
|
179 | 179 | return $data; |
180 | 180 | } |
181 | 181 | |
182 | 182 | $path = explode('.', rtrim($path, '.')); |
183 | 183 | |
184 | - foreach ($path as $step) { |
|
185 | - if (!is_array($data) || !array_key_exists($step, $data)) { |
|
184 | + foreach ($path as $step){ |
|
185 | + if (!is_array($data) || !array_key_exists($step, $data)){ |
|
186 | 186 | throw new DotNotFoundException("Unable to find requested element '{$name}'"); |
187 | 187 | } |
188 | 188 |
@@ -57,9 +57,12 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function all(): array |
59 | 59 | { |
60 | - try { |
|
60 | + try |
|
61 | + { |
|
61 | 62 | return $this->dotGet(''); |
62 | - } catch (DotNotFoundException $e) { |
|
63 | + } |
|
64 | + catch (DotNotFoundException $e) |
|
65 | + { |
|
63 | 66 | return []; |
64 | 67 | } |
65 | 68 | } |
@@ -85,7 +88,8 @@ discard block |
||
85 | 88 | { |
86 | 89 | $result = array_intersect_key($this->all(), array_flip($keys)); |
87 | 90 | ; |
88 | - if (!$fill) { |
|
91 | + if (!$fill) |
|
92 | + { |
|
89 | 93 | return $result; |
90 | 94 | } |
91 | 95 | |
@@ -108,9 +112,12 @@ discard block |
||
108 | 112 | */ |
109 | 113 | public function has(string $name): bool |
110 | 114 | { |
111 | - try { |
|
115 | + try |
|
116 | + { |
|
112 | 117 | $this->dotGet($name); |
113 | - } catch (DotNotFoundException $e) { |
|
118 | + } |
|
119 | + catch (DotNotFoundException $e) |
|
120 | + { |
|
114 | 121 | return false; |
115 | 122 | } |
116 | 123 | |
@@ -134,9 +141,12 @@ discard block |
||
134 | 141 | */ |
135 | 142 | public function get(string $name, $default = null) |
136 | 143 | { |
137 | - try { |
|
144 | + try |
|
145 | + { |
|
138 | 146 | return $this->dotGet($name); |
139 | - } catch (DotNotFoundException $e) { |
|
147 | + } |
|
148 | + catch (DotNotFoundException $e) |
|
149 | + { |
|
140 | 150 | return $default; |
141 | 151 | } |
142 | 152 | } |
@@ -175,14 +185,17 @@ discard block |
||
175 | 185 | |
176 | 186 | //Generating path relative to a given name and prefix |
177 | 187 | $path = (!empty($this->prefix) ? $this->prefix . '.' : '') . $name; |
178 | - if (empty($path)) { |
|
188 | + if (empty($path)) |
|
189 | + { |
|
179 | 190 | return $data; |
180 | 191 | } |
181 | 192 | |
182 | 193 | $path = explode('.', rtrim($path, '.')); |
183 | 194 | |
184 | - foreach ($path as $step) { |
|
185 | - if (!is_array($data) || !array_key_exists($step, $data)) { |
|
195 | + foreach ($path as $step) |
|
196 | + { |
|
197 | + if (!is_array($data) || !array_key_exists($step, $data)) |
|
198 | + { |
|
186 | 199 | throw new DotNotFoundException("Unable to find requested element '{$name}'"); |
187 | 200 | } |
188 | 201 |
@@ -388,7 +388,6 @@ discard block |
||
388 | 388 | /** |
389 | 389 | * @param string $name |
390 | 390 | * @param mixed $default |
391 | - |
|
392 | 391 | * @return mixed |
393 | 392 | */ |
394 | 393 | public function query(string $name, $default = null) |
@@ -399,7 +398,6 @@ discard block |
||
399 | 398 | /** |
400 | 399 | * @param string $name |
401 | 400 | * @param mixed $default |
402 | - |
|
403 | 401 | * @return mixed |
404 | 402 | */ |
405 | 403 | public function cookie(string $name, $default = null) |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | { |
144 | 144 | $input = clone $this; |
145 | 145 | |
146 | - if ($add) { |
|
147 | - $input->prefix .= '.' . $prefix; |
|
146 | + if ($add){ |
|
147 | + $input->prefix .= '.'.$prefix; |
|
148 | 148 | $input->prefix = trim($input->prefix, '.'); |
149 | - } else { |
|
149 | + }else{ |
|
150 | 150 | $input->prefix = $prefix; |
151 | 151 | } |
152 | 152 | |
@@ -162,12 +162,12 @@ discard block |
||
162 | 162 | { |
163 | 163 | $path = $this->uri()->getPath(); |
164 | 164 | |
165 | - if (empty($path)) { |
|
165 | + if (empty($path)){ |
|
166 | 166 | return '/'; |
167 | 167 | } |
168 | 168 | |
169 | - if ($path[0] !== '/') { |
|
170 | - return '/' . $path; |
|
169 | + if ($path[0] !== '/'){ |
|
170 | + return '/'.$path; |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | return $path; |
@@ -192,9 +192,9 @@ discard block |
||
192 | 192 | */ |
193 | 193 | public function request(): Request |
194 | 194 | { |
195 | - try { |
|
195 | + try{ |
|
196 | 196 | $request = $this->container->get(Request::class); |
197 | - } catch (ContainerExceptionInterface $e) { |
|
197 | + }catch (ContainerExceptionInterface $e){ |
|
198 | 198 | throw new ScopeException( |
199 | 199 | 'Unable to get `ServerRequestInterface` in active container scope', |
200 | 200 | $e->getCode(), |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | } |
204 | 204 | |
205 | 205 | //Flushing input state |
206 | - if ($this->request !== $request) { |
|
206 | + if ($this->request !== $request){ |
|
207 | 207 | $this->bags = []; |
208 | 208 | $this->request = $request; |
209 | 209 | } |
@@ -265,16 +265,16 @@ discard block |
||
265 | 265 | public function isJsonExpected(bool $softMatch = false): bool |
266 | 266 | { |
267 | 267 | $acceptHeader = AcceptHeader::fromString($this->request()->getHeaderLine('Accept')); |
268 | - foreach ($this->jsonTypes as $jsonType) { |
|
269 | - if ($acceptHeader->has($jsonType)) { |
|
268 | + foreach ($this->jsonTypes as $jsonType){ |
|
269 | + if ($acceptHeader->has($jsonType)){ |
|
270 | 270 | return true; |
271 | 271 | } |
272 | 272 | } |
273 | 273 | |
274 | - if ($softMatch) { |
|
275 | - foreach ($acceptHeader->getAll() as $item) { |
|
274 | + if ($softMatch){ |
|
275 | + foreach ($acceptHeader->getAll() as $item){ |
|
276 | 276 | $itemValue = strtolower($item->getValue()); |
277 | - if (str_ends_with($itemValue, '/json') || str_ends_with($itemValue, '+json')) { |
|
277 | + if (str_ends_with($itemValue, '/json') || str_ends_with($itemValue, '+json')){ |
|
278 | 278 | return true; |
279 | 279 | } |
280 | 280 | } |
@@ -321,18 +321,18 @@ discard block |
||
321 | 321 | // ensure proper request association |
322 | 322 | $this->request(); |
323 | 323 | |
324 | - if (isset($this->bags[$name])) { |
|
324 | + if (isset($this->bags[$name])){ |
|
325 | 325 | return $this->bags[$name]; |
326 | 326 | } |
327 | 327 | |
328 | - if (!isset($this->bagAssociations[$name])) { |
|
328 | + if (!isset($this->bagAssociations[$name])){ |
|
329 | 329 | throw new InputException("Undefined input bag '{$name}'"); |
330 | 330 | } |
331 | 331 | |
332 | 332 | $class = $this->bagAssociations[$name]['class']; |
333 | 333 | $data = call_user_func([$this->request(), $this->bagAssociations[$name]['source']]); |
334 | 334 | |
335 | - if (!is_array($data)) { |
|
335 | + if (!is_array($data)){ |
|
336 | 336 | $data = (array)$data; |
337 | 337 | } |
338 | 338 |
@@ -143,10 +143,13 @@ discard block |
||
143 | 143 | { |
144 | 144 | $input = clone $this; |
145 | 145 | |
146 | - if ($add) { |
|
146 | + if ($add) |
|
147 | + { |
|
147 | 148 | $input->prefix .= '.' . $prefix; |
148 | 149 | $input->prefix = trim($input->prefix, '.'); |
149 | - } else { |
|
150 | + } |
|
151 | + else |
|
152 | + { |
|
150 | 153 | $input->prefix = $prefix; |
151 | 154 | } |
152 | 155 | |
@@ -162,11 +165,13 @@ discard block |
||
162 | 165 | { |
163 | 166 | $path = $this->uri()->getPath(); |
164 | 167 | |
165 | - if (empty($path)) { |
|
168 | + if (empty($path)) |
|
169 | + { |
|
166 | 170 | return '/'; |
167 | 171 | } |
168 | 172 | |
169 | - if ($path[0] !== '/') { |
|
173 | + if ($path[0] !== '/') |
|
174 | + { |
|
170 | 175 | return '/' . $path; |
171 | 176 | } |
172 | 177 | |
@@ -192,9 +197,12 @@ discard block |
||
192 | 197 | */ |
193 | 198 | public function request(): Request |
194 | 199 | { |
195 | - try { |
|
200 | + try |
|
201 | + { |
|
196 | 202 | $request = $this->container->get(Request::class); |
197 | - } catch (ContainerExceptionInterface $e) { |
|
203 | + } |
|
204 | + catch (ContainerExceptionInterface $e) |
|
205 | + { |
|
198 | 206 | throw new ScopeException( |
199 | 207 | 'Unable to get `ServerRequestInterface` in active container scope', |
200 | 208 | $e->getCode(), |
@@ -203,7 +211,8 @@ discard block |
||
203 | 211 | } |
204 | 212 | |
205 | 213 | //Flushing input state |
206 | - if ($this->request !== $request) { |
|
214 | + if ($this->request !== $request) |
|
215 | + { |
|
207 | 216 | $this->bags = []; |
208 | 217 | $this->request = $request; |
209 | 218 | } |
@@ -265,16 +274,21 @@ discard block |
||
265 | 274 | public function isJsonExpected(bool $softMatch = false): bool |
266 | 275 | { |
267 | 276 | $acceptHeader = AcceptHeader::fromString($this->request()->getHeaderLine('Accept')); |
268 | - foreach ($this->jsonTypes as $jsonType) { |
|
269 | - if ($acceptHeader->has($jsonType)) { |
|
277 | + foreach ($this->jsonTypes as $jsonType) |
|
278 | + { |
|
279 | + if ($acceptHeader->has($jsonType)) |
|
280 | + { |
|
270 | 281 | return true; |
271 | 282 | } |
272 | 283 | } |
273 | 284 | |
274 | - if ($softMatch) { |
|
275 | - foreach ($acceptHeader->getAll() as $item) { |
|
285 | + if ($softMatch) |
|
286 | + { |
|
287 | + foreach ($acceptHeader->getAll() as $item) |
|
288 | + { |
|
276 | 289 | $itemValue = strtolower($item->getValue()); |
277 | - if (str_ends_with($itemValue, '/json') || str_ends_with($itemValue, '+json')) { |
|
290 | + if (str_ends_with($itemValue, '/json') || str_ends_with($itemValue, '+json')) |
|
291 | + { |
|
278 | 292 | return true; |
279 | 293 | } |
280 | 294 | } |
@@ -321,18 +335,21 @@ discard block |
||
321 | 335 | // ensure proper request association |
322 | 336 | $this->request(); |
323 | 337 | |
324 | - if (isset($this->bags[$name])) { |
|
338 | + if (isset($this->bags[$name])) |
|
339 | + { |
|
325 | 340 | return $this->bags[$name]; |
326 | 341 | } |
327 | 342 | |
328 | - if (!isset($this->bagAssociations[$name])) { |
|
343 | + if (!isset($this->bagAssociations[$name])) |
|
344 | + { |
|
329 | 345 | throw new InputException("Undefined input bag '{$name}'"); |
330 | 346 | } |
331 | 347 | |
332 | 348 | $class = $this->bagAssociations[$name]['class']; |
333 | 349 | $data = call_user_func([$this->request(), $this->bagAssociations[$name]['source']]); |
334 | 350 | |
335 | - if (!is_array($data)) { |
|
351 | + if (!is_array($data)) |
|
352 | + { |
|
336 | 353 | $data = (array)$data; |
337 | 354 | } |
338 | 355 |
@@ -30,7 +30,6 @@ discard block |
||
30 | 30 | * |
31 | 31 | * |
32 | 32 | * @param bool|string $implode Implode header lines, false to return header as array. |
33 | - |
|
34 | 33 | * @return string|array |
35 | 34 | */ |
36 | 35 | public function get(string $name, $default = null, $implode = ',') |
@@ -69,7 +68,6 @@ discard block |
||
69 | 68 | * Normalize header name. |
70 | 69 | * |
71 | 70 | * @param string $header |
72 | - |
|
73 | 71 | * @return string |
74 | 72 | */ |
75 | 73 | protected function normalize(string $header): string |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | { |
38 | 38 | $value = parent::get($this->normalize($name), $default); |
39 | 39 | |
40 | - if (!empty($implode) && is_array($value)) { |
|
40 | + if (!empty($implode) && is_array($value)){ |
|
41 | 41 | return implode($implode, $value); |
42 | 42 | } |
43 | 43 | |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | |
56 | 56 | $values = parent::fetch($keys, $fill, $filler); |
57 | 57 | |
58 | - if (!empty($implode)) { |
|
59 | - foreach ($values as &$value) { |
|
58 | + if (!empty($implode)){ |
|
59 | + foreach ($values as &$value){ |
|
60 | 60 | $value = implode($implode, $value); |
61 | 61 | unset($value); |
62 | 62 | } |
@@ -37,7 +37,8 @@ discard block |
||
37 | 37 | { |
38 | 38 | $value = parent::get($this->normalize($name), $default); |
39 | 39 | |
40 | - if (!empty($implode) && is_array($value)) { |
|
40 | + if (!empty($implode) && is_array($value)) |
|
41 | + { |
|
41 | 42 | return implode($implode, $value); |
42 | 43 | } |
43 | 44 | |
@@ -55,8 +56,10 @@ discard block |
||
55 | 56 | |
56 | 57 | $values = parent::fetch($keys, $fill, $filler); |
57 | 58 | |
58 | - if (!empty($implode)) { |
|
59 | - foreach ($values as &$value) { |
|
59 | + if (!empty($implode)) |
|
60 | + { |
|
61 | + foreach ($values as &$value) |
|
62 | + { |
|
60 | 63 | $value = implode($implode, $value); |
61 | 64 | unset($value); |
62 | 65 | } |