@@ -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 |
@@ -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 | } |
@@ -30,7 +30,6 @@ |
||
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 = ',') |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | ResponseFactoryInterface $responseFactory, |
47 | 47 | StreamFactoryInterface $streamFactory, |
48 | 48 | FilesInterface $files |
49 | - ) { |
|
49 | + ){ |
|
50 | 50 | $this->responseFactory = $responseFactory; |
51 | 51 | $this->streamFactory = $streamFactory; |
52 | 52 | $this->files = $files; |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function redirect($uri, int $code = 302): ResponseInterface |
74 | 74 | { |
75 | - if (!is_string($uri) && !$uri instanceof UriInterface) { |
|
75 | + if (!is_string($uri) && !$uri instanceof UriInterface){ |
|
76 | 76 | throw new ResponseException('Redirect allowed only for string or UriInterface uris'); |
77 | 77 | } |
78 | 78 | |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | string $name = '', |
109 | 109 | string $mime = 'application/octet-stream' |
110 | 110 | ): ResponseInterface { |
111 | - if (empty($name)) { |
|
112 | - if (!is_string($filename)) { |
|
111 | + if (empty($name)){ |
|
112 | + if (!is_string($filename)){ |
|
113 | 113 | throw new ResponseException('Unable to resolve public filename'); |
114 | 114 | } |
115 | 115 | |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | $response = $response->withHeader('Content-Length', (string)$stream->getSize()); |
124 | 124 | $response = $response->withHeader( |
125 | 125 | 'Content-Disposition', |
126 | - 'attachment; filename="' . addcslashes($name, '"') . '"' |
|
126 | + 'attachment; filename="'.addcslashes($name, '"').'"' |
|
127 | 127 | ); |
128 | 128 | |
129 | 129 | return $response->withBody($stream); |
@@ -156,19 +156,19 @@ discard block |
||
156 | 156 | */ |
157 | 157 | private function getStream($file): StreamInterface |
158 | 158 | { |
159 | - if ($file instanceof StreamableInterface) { |
|
159 | + if ($file instanceof StreamableInterface){ |
|
160 | 160 | return $file->getStream(); |
161 | 161 | } |
162 | 162 | |
163 | - if ($file instanceof StreamInterface) { |
|
163 | + if ($file instanceof StreamInterface){ |
|
164 | 164 | return $file; |
165 | 165 | } |
166 | 166 | |
167 | - if (is_resource($file)) { |
|
167 | + if (is_resource($file)){ |
|
168 | 168 | return $this->streamFactory->createStreamFromResource($file); |
169 | 169 | } |
170 | 170 | |
171 | - if (!$this->files->isFile($file)) { |
|
171 | + if (!$this->files->isFile($file)){ |
|
172 | 172 | throw new ResponseException('Unable to allocate response body stream, file does not exist'); |
173 | 173 | } |
174 | 174 |
@@ -72,7 +72,8 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function redirect($uri, int $code = 302): ResponseInterface |
74 | 74 | { |
75 | - if (!is_string($uri) && !$uri instanceof UriInterface) { |
|
75 | + if (!is_string($uri) && !$uri instanceof UriInterface) |
|
76 | + { |
|
76 | 77 | throw new ResponseException('Redirect allowed only for string or UriInterface uris'); |
77 | 78 | } |
78 | 79 | |
@@ -108,8 +109,10 @@ discard block |
||
108 | 109 | string $name = '', |
109 | 110 | string $mime = 'application/octet-stream' |
110 | 111 | ): ResponseInterface { |
111 | - if (empty($name)) { |
|
112 | - if (!is_string($filename)) { |
|
112 | + if (empty($name)) |
|
113 | + { |
|
114 | + if (!is_string($filename)) |
|
115 | + { |
|
113 | 116 | throw new ResponseException('Unable to resolve public filename'); |
114 | 117 | } |
115 | 118 | |
@@ -156,19 +159,23 @@ discard block |
||
156 | 159 | */ |
157 | 160 | private function getStream($file): StreamInterface |
158 | 161 | { |
159 | - if ($file instanceof StreamableInterface) { |
|
162 | + if ($file instanceof StreamableInterface) |
|
163 | + { |
|
160 | 164 | return $file->getStream(); |
161 | 165 | } |
162 | 166 | |
163 | - if ($file instanceof StreamInterface) { |
|
167 | + if ($file instanceof StreamInterface) |
|
168 | + { |
|
164 | 169 | return $file; |
165 | 170 | } |
166 | 171 | |
167 | - if (is_resource($file)) { |
|
172 | + if (is_resource($file)) |
|
173 | + { |
|
168 | 174 | return $this->streamFactory->createStreamFromResource($file); |
169 | 175 | } |
170 | 176 | |
171 | - if (!$this->files->isFile($file)) { |
|
177 | + if (!$this->files->isFile($file)) |
|
178 | + { |
|
172 | 179 | throw new ResponseException('Unable to allocate response body stream, file does not exist'); |
173 | 180 | } |
174 | 181 |
@@ -127,9 +127,9 @@ |
||
127 | 127 | $cookie = new Cookie('', '', 0, '', '', $secure, false, $sameSite); |
128 | 128 | $this->assertSame($expected, $cookie->getSameSite()); |
129 | 129 | |
130 | - if ($expected === null) { |
|
130 | + if ($expected === null){ |
|
131 | 131 | $this->assertStringNotContainsString('SameSite=', $cookie->createHeader()); |
132 | - } else { |
|
132 | + }else{ |
|
133 | 133 | $this->assertStringContainsString("SameSite=$expected", $cookie->createHeader()); |
134 | 134 | } |
135 | 135 | } |
@@ -127,9 +127,12 @@ |
||
127 | 127 | $cookie = new Cookie('', '', 0, '', '', $secure, false, $sameSite); |
128 | 128 | $this->assertSame($expected, $cookie->getSameSite()); |
129 | 129 | |
130 | - if ($expected === null) { |
|
130 | + if ($expected === null) |
|
131 | + { |
|
131 | 132 | $this->assertStringNotContainsString('SameSite=', $cookie->createHeader()); |
132 | - } else { |
|
133 | + } |
|
134 | + else |
|
135 | + { |
|
133 | 136 | $this->assertStringContainsString("SameSite=$expected", $cookie->createHeader()); |
134 | 137 | } |
135 | 138 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | public function testScope(): void |
57 | 57 | { |
58 | 58 | $core = $this->httpCore([CookiesMiddleware::class]); |
59 | - $core->setHandler(function ($r) { |
|
59 | + $core->setHandler(function ($r){ |
|
60 | 60 | $this->assertInstanceOf( |
61 | 61 | CookieQueue::class, |
62 | 62 | $this->container->get(ServerRequestInterface::class) |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | public function testSetEncryptedCookie(): void |
81 | 81 | { |
82 | 82 | $core = $this->httpCore([CookiesMiddleware::class]); |
83 | - $core->setHandler(function ($r) { |
|
83 | + $core->setHandler(function ($r){ |
|
84 | 84 | $this->container->get(ServerRequestInterface::class) |
85 | 85 | ->getAttribute(CookieQueue::ATTRIBUTE)->set('name', 'value'); |
86 | 86 | |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | public function testSetNotProtectedCookie(): void |
103 | 103 | { |
104 | 104 | $core = $this->httpCore([CookiesMiddleware::class]); |
105 | - $core->setHandler(function ($r) { |
|
105 | + $core->setHandler(function ($r){ |
|
106 | 106 | $this->container->get(ServerRequestInterface::class) |
107 | 107 | ->getAttribute(CookieQueue::ATTRIBUTE)->set('PHPSESSID', 'value'); |
108 | 108 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | public function testDecrypt(): void |
122 | 122 | { |
123 | 123 | $core = $this->httpCore([CookiesMiddleware::class]); |
124 | - $core->setHandler(function ($r) { |
|
124 | + $core->setHandler(function ($r){ |
|
125 | 125 | |
126 | 126 | /** |
127 | 127 | * @var ServerRequest $r |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | public function testDecryptArray(): void |
140 | 140 | { |
141 | 141 | $core = $this->httpCore([CookiesMiddleware::class]); |
142 | - $core->setHandler(function ($r) { |
|
142 | + $core->setHandler(function ($r){ |
|
143 | 143 | |
144 | 144 | /** |
145 | 145 | * @var ServerRequest $r |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | public function testDecryptBroken(): void |
158 | 158 | { |
159 | 159 | $core = $this->httpCore([CookiesMiddleware::class]); |
160 | - $core->setHandler(function ($r) { |
|
160 | + $core->setHandler(function ($r){ |
|
161 | 161 | |
162 | 162 | /** |
163 | 163 | * @var ServerRequest $r |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | return $r->getCookieParams()['name']; |
166 | 166 | }); |
167 | 167 | |
168 | - $value = $this->container->get(EncrypterInterface::class)->encrypt('cookie-value') . 'BROKEN'; |
|
168 | + $value = $this->container->get(EncrypterInterface::class)->encrypt('cookie-value').'BROKEN'; |
|
169 | 169 | |
170 | 170 | $response = $this->get($core, '/', [], [], ['name' => $value]); |
171 | 171 | $this->assertSame(200, $response->getStatusCode()); |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | public function testDelete(): void |
176 | 176 | { |
177 | 177 | $core = $this->httpCore([CookiesMiddleware::class]); |
178 | - $core->setHandler(function ($r) { |
|
178 | + $core->setHandler(function ($r){ |
|
179 | 179 | $this->container->get(ServerRequestInterface::class) |
180 | 180 | ->getAttribute(CookieQueue::ATTRIBUTE)->set('name', 'value'); |
181 | 181 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | ])); |
204 | 204 | |
205 | 205 | $core = $this->httpCore([CookiesMiddleware::class]); |
206 | - $core->setHandler(function ($r) { |
|
206 | + $core->setHandler(function ($r){ |
|
207 | 207 | $this->container->get(ServerRequestInterface::class) |
208 | 208 | ->getAttribute(CookieQueue::ATTRIBUTE)->set('name', 'value'); |
209 | 209 | |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | ])); |
229 | 229 | |
230 | 230 | $core = $this->httpCore([CookiesMiddleware::class]); |
231 | - $core->setHandler(function ($r) { |
|
231 | + $core->setHandler(function ($r){ |
|
232 | 232 | |
233 | 233 | /** |
234 | 234 | * @var ServerRequest $r |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | ])); |
253 | 253 | |
254 | 254 | $core = $this->httpCore([CookiesMiddleware::class]); |
255 | - $core->setHandler(function ($r) { |
|
255 | + $core->setHandler(function ($r){ |
|
256 | 256 | $this->container->get(ServerRequestInterface::class) |
257 | 257 | ->getAttribute(CookieQueue::ATTRIBUTE)->set('name', 'value'); |
258 | 258 | |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | $cookies = $this->fetchCookies($response); |
267 | 267 | $this->assertArrayHasKey('name', $cookies); |
268 | 268 | |
269 | - $core->setHandler(function ($r) { |
|
269 | + $core->setHandler(function ($r){ |
|
270 | 270 | return $r->getCookieParams()['name']; |
271 | 271 | }); |
272 | 272 | |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | { |
327 | 327 | $result = []; |
328 | 328 | |
329 | - foreach ($response->getHeaders() as $line) { |
|
329 | + foreach ($response->getHeaders() as $line){ |
|
330 | 330 | $cookie = explode('=', implode('', $line)); |
331 | 331 | $result[$cookie[0]] = rawurldecode(substr( |
332 | 332 | (string)$cookie[1], |
@@ -56,7 +56,8 @@ discard block |
||
56 | 56 | public function testScope(): void |
57 | 57 | { |
58 | 58 | $core = $this->httpCore([CookiesMiddleware::class]); |
59 | - $core->setHandler(function ($r) { |
|
59 | + $core->setHandler(function ($r) |
|
60 | + { |
|
60 | 61 | $this->assertInstanceOf( |
61 | 62 | CookieQueue::class, |
62 | 63 | $this->container->get(ServerRequestInterface::class) |
@@ -80,7 +81,8 @@ discard block |
||
80 | 81 | public function testSetEncryptedCookie(): void |
81 | 82 | { |
82 | 83 | $core = $this->httpCore([CookiesMiddleware::class]); |
83 | - $core->setHandler(function ($r) { |
|
84 | + $core->setHandler(function ($r) |
|
85 | + { |
|
84 | 86 | $this->container->get(ServerRequestInterface::class) |
85 | 87 | ->getAttribute(CookieQueue::ATTRIBUTE)->set('name', 'value'); |
86 | 88 | |
@@ -102,7 +104,8 @@ discard block |
||
102 | 104 | public function testSetNotProtectedCookie(): void |
103 | 105 | { |
104 | 106 | $core = $this->httpCore([CookiesMiddleware::class]); |
105 | - $core->setHandler(function ($r) { |
|
107 | + $core->setHandler(function ($r) |
|
108 | + { |
|
106 | 109 | $this->container->get(ServerRequestInterface::class) |
107 | 110 | ->getAttribute(CookieQueue::ATTRIBUTE)->set('PHPSESSID', 'value'); |
108 | 111 | |
@@ -121,7 +124,8 @@ discard block |
||
121 | 124 | public function testDecrypt(): void |
122 | 125 | { |
123 | 126 | $core = $this->httpCore([CookiesMiddleware::class]); |
124 | - $core->setHandler(function ($r) { |
|
127 | + $core->setHandler(function ($r) |
|
128 | + { |
|
125 | 129 | |
126 | 130 | /** |
127 | 131 | * @var ServerRequest $r |
@@ -139,7 +143,8 @@ discard block |
||
139 | 143 | public function testDecryptArray(): void |
140 | 144 | { |
141 | 145 | $core = $this->httpCore([CookiesMiddleware::class]); |
142 | - $core->setHandler(function ($r) { |
|
146 | + $core->setHandler(function ($r) |
|
147 | + { |
|
143 | 148 | |
144 | 149 | /** |
145 | 150 | * @var ServerRequest $r |
@@ -157,7 +162,8 @@ discard block |
||
157 | 162 | public function testDecryptBroken(): void |
158 | 163 | { |
159 | 164 | $core = $this->httpCore([CookiesMiddleware::class]); |
160 | - $core->setHandler(function ($r) { |
|
165 | + $core->setHandler(function ($r) |
|
166 | + { |
|
161 | 167 | |
162 | 168 | /** |
163 | 169 | * @var ServerRequest $r |
@@ -175,7 +181,8 @@ discard block |
||
175 | 181 | public function testDelete(): void |
176 | 182 | { |
177 | 183 | $core = $this->httpCore([CookiesMiddleware::class]); |
178 | - $core->setHandler(function ($r) { |
|
184 | + $core->setHandler(function ($r) |
|
185 | + { |
|
179 | 186 | $this->container->get(ServerRequestInterface::class) |
180 | 187 | ->getAttribute(CookieQueue::ATTRIBUTE)->set('name', 'value'); |
181 | 188 | |
@@ -203,7 +210,8 @@ discard block |
||
203 | 210 | ])); |
204 | 211 | |
205 | 212 | $core = $this->httpCore([CookiesMiddleware::class]); |
206 | - $core->setHandler(function ($r) { |
|
213 | + $core->setHandler(function ($r) |
|
214 | + { |
|
207 | 215 | $this->container->get(ServerRequestInterface::class) |
208 | 216 | ->getAttribute(CookieQueue::ATTRIBUTE)->set('name', 'value'); |
209 | 217 | |
@@ -228,7 +236,8 @@ discard block |
||
228 | 236 | ])); |
229 | 237 | |
230 | 238 | $core = $this->httpCore([CookiesMiddleware::class]); |
231 | - $core->setHandler(function ($r) { |
|
239 | + $core->setHandler(function ($r) |
|
240 | + { |
|
232 | 241 | |
233 | 242 | /** |
234 | 243 | * @var ServerRequest $r |
@@ -252,7 +261,8 @@ discard block |
||
252 | 261 | ])); |
253 | 262 | |
254 | 263 | $core = $this->httpCore([CookiesMiddleware::class]); |
255 | - $core->setHandler(function ($r) { |
|
264 | + $core->setHandler(function ($r) |
|
265 | + { |
|
256 | 266 | $this->container->get(ServerRequestInterface::class) |
257 | 267 | ->getAttribute(CookieQueue::ATTRIBUTE)->set('name', 'value'); |
258 | 268 | |
@@ -266,7 +276,8 @@ discard block |
||
266 | 276 | $cookies = $this->fetchCookies($response); |
267 | 277 | $this->assertArrayHasKey('name', $cookies); |
268 | 278 | |
269 | - $core->setHandler(function ($r) { |
|
279 | + $core->setHandler(function ($r) |
|
280 | + { |
|
270 | 281 | return $r->getCookieParams()['name']; |
271 | 282 | }); |
272 | 283 | |
@@ -326,7 +337,8 @@ discard block |
||
326 | 337 | { |
327 | 338 | $result = []; |
328 | 339 | |
329 | - foreach ($response->getHeaders() as $line) { |
|
340 | + foreach ($response->getHeaders() as $line) |
|
341 | + { |
|
330 | 342 | $cookie = explode('=', implode('', $line)); |
331 | 343 | $result[$cookie[0]] = rawurldecode(substr( |
332 | 344 | (string)$cookie[1], |
@@ -37,7 +37,7 @@ |
||
37 | 37 | $response = new Response('php://memory', $code, []); |
38 | 38 | $response = $response->withStatus($code, $reasonPhrase); |
39 | 39 | |
40 | - foreach ($this->config->getBaseHeaders() as $header => $value) { |
|
40 | + foreach ($this->config->getBaseHeaders() as $header => $value){ |
|
41 | 41 | $response = $response->withAddedHeader($header, $value); |
42 | 42 | } |
43 | 43 |
@@ -37,7 +37,8 @@ |
||
37 | 37 | $response = new Response('php://memory', $code, []); |
38 | 38 | $response = $response->withStatus($code, $reasonPhrase); |
39 | 39 | |
40 | - foreach ($this->config->getBaseHeaders() as $header => $value) { |
|
40 | + foreach ($this->config->getBaseHeaders() as $header => $value) |
|
41 | + { |
|
41 | 42 | $response = $response->withAddedHeader($header, $value); |
42 | 43 | } |
43 | 44 |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | bool $secure = false, |
130 | 130 | bool $httpOnly = true, |
131 | 131 | ?string $sameSite = null |
132 | - ) { |
|
132 | + ){ |
|
133 | 133 | $this->name = $name; |
134 | 134 | $this->value = $value; |
135 | 135 | $this->lifetime = $lifetime; |
@@ -253,30 +253,30 @@ discard block |
||
253 | 253 | */ |
254 | 254 | public function createHeader(): string |
255 | 255 | { |
256 | - $header = [rawurlencode($this->name) . '=' . rawurlencode((string)$this->value)]; |
|
256 | + $header = [rawurlencode($this->name).'='.rawurlencode((string)$this->value)]; |
|
257 | 257 | |
258 | - if ($this->lifetime !== null) { |
|
259 | - $header[] = 'Expires=' . gmdate(\DateTime::COOKIE, $this->getExpires()); |
|
258 | + if ($this->lifetime !== null){ |
|
259 | + $header[] = 'Expires='.gmdate(\DateTime::COOKIE, $this->getExpires()); |
|
260 | 260 | $header[] = "Max-Age={$this->lifetime}"; |
261 | 261 | } |
262 | 262 | |
263 | - if (!empty($this->path)) { |
|
263 | + if (!empty($this->path)){ |
|
264 | 264 | $header[] = "Path={$this->path}"; |
265 | 265 | } |
266 | 266 | |
267 | - if (!empty($this->domain)) { |
|
267 | + if (!empty($this->domain)){ |
|
268 | 268 | $header[] = "Domain={$this->domain}"; |
269 | 269 | } |
270 | 270 | |
271 | - if ($this->secure) { |
|
271 | + if ($this->secure){ |
|
272 | 272 | $header[] = 'Secure'; |
273 | 273 | } |
274 | 274 | |
275 | - if ($this->httpOnly) { |
|
275 | + if ($this->httpOnly){ |
|
276 | 276 | $header[] = 'HttpOnly'; |
277 | 277 | } |
278 | 278 | |
279 | - if ($this->sameSite->get() !== null) { |
|
279 | + if ($this->sameSite->get() !== null){ |
|
280 | 280 | $header[] = "SameSite={$this->sameSite->get()}"; |
281 | 281 | } |
282 | 282 | |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | */ |
293 | 293 | public function getExpires(): ?int |
294 | 294 | { |
295 | - if ($this->lifetime === null) { |
|
295 | + if ($this->lifetime === null){ |
|
296 | 296 | return null; |
297 | 297 | } |
298 | 298 |
@@ -255,28 +255,34 @@ discard block |
||
255 | 255 | { |
256 | 256 | $header = [rawurlencode($this->name) . '=' . rawurlencode((string)$this->value)]; |
257 | 257 | |
258 | - if ($this->lifetime !== null) { |
|
258 | + if ($this->lifetime !== null) |
|
259 | + { |
|
259 | 260 | $header[] = 'Expires=' . gmdate(\DateTime::COOKIE, $this->getExpires()); |
260 | 261 | $header[] = "Max-Age={$this->lifetime}"; |
261 | 262 | } |
262 | 263 | |
263 | - if (!empty($this->path)) { |
|
264 | + if (!empty($this->path)) |
|
265 | + { |
|
264 | 266 | $header[] = "Path={$this->path}"; |
265 | 267 | } |
266 | 268 | |
267 | - if (!empty($this->domain)) { |
|
269 | + if (!empty($this->domain)) |
|
270 | + { |
|
268 | 271 | $header[] = "Domain={$this->domain}"; |
269 | 272 | } |
270 | 273 | |
271 | - if ($this->secure) { |
|
274 | + if ($this->secure) |
|
275 | + { |
|
272 | 276 | $header[] = 'Secure'; |
273 | 277 | } |
274 | 278 | |
275 | - if ($this->httpOnly) { |
|
279 | + if ($this->httpOnly) |
|
280 | + { |
|
276 | 281 | $header[] = 'HttpOnly'; |
277 | 282 | } |
278 | 283 | |
279 | - if ($this->sameSite->get() !== null) { |
|
284 | + if ($this->sameSite->get() !== null) |
|
285 | + { |
|
280 | 286 | $header[] = "SameSite={$this->sameSite->get()}"; |
281 | 287 | } |
282 | 288 | |
@@ -292,7 +298,8 @@ discard block |
||
292 | 298 | */ |
293 | 299 | public function getExpires(): ?int |
294 | 300 | { |
295 | - if ($this->lifetime === null) { |
|
301 | + if ($this->lifetime === null) |
|
302 | + { |
|
296 | 303 | return null; |
297 | 304 | } |
298 | 305 |
@@ -92,12 +92,12 @@ discard block |
||
92 | 92 | bool $httpOnly = true, |
93 | 93 | ?string $sameSite = null |
94 | 94 | ): self { |
95 | - if (is_null($domain)) { |
|
95 | + if (is_null($domain)){ |
|
96 | 96 | //Let's resolve domain via config |
97 | 97 | $domain = $this->domain; |
98 | 98 | } |
99 | 99 | |
100 | - if (is_null($secure)) { |
|
100 | + if (is_null($secure)){ |
|
101 | 101 | $secure = $this->secure; |
102 | 102 | } |
103 | 103 | |
@@ -127,8 +127,8 @@ discard block |
||
127 | 127 | */ |
128 | 128 | public function delete(string $name): void |
129 | 129 | { |
130 | - foreach ($this->scheduled as $index => $cookie) { |
|
131 | - if ($cookie->getName() === $name) { |
|
130 | + foreach ($this->scheduled as $index => $cookie){ |
|
131 | + if ($cookie->getName() === $name){ |
|
132 | 132 | unset($this->scheduled[$index]); |
133 | 133 | } |
134 | 134 | } |
@@ -92,12 +92,14 @@ discard block |
||
92 | 92 | bool $httpOnly = true, |
93 | 93 | ?string $sameSite = null |
94 | 94 | ): self { |
95 | - if (is_null($domain)) { |
|
95 | + if (is_null($domain)) |
|
96 | + { |
|
96 | 97 | //Let's resolve domain via config |
97 | 98 | $domain = $this->domain; |
98 | 99 | } |
99 | 100 | |
100 | - if (is_null($secure)) { |
|
101 | + if (is_null($secure)) |
|
102 | + { |
|
101 | 103 | $secure = $this->secure; |
102 | 104 | } |
103 | 105 | |
@@ -127,8 +129,10 @@ discard block |
||
127 | 129 | */ |
128 | 130 | public function delete(string $name): void |
129 | 131 | { |
130 | - foreach ($this->scheduled as $index => $cookie) { |
|
131 | - if ($cookie->getName() === $name) { |
|
132 | + foreach ($this->scheduled as $index => $cookie) |
|
133 | + { |
|
134 | + if ($cookie->getName() === $name) |
|
135 | + { |
|
132 | 136 | unset($this->scheduled[$index]); |
133 | 137 | } |
134 | 138 | } |
@@ -53,22 +53,22 @@ |
||
53 | 53 | public function resolveDomain(UriInterface $uri): ?string |
54 | 54 | { |
55 | 55 | $host = $uri->getHost(); |
56 | - if (empty($host)) { |
|
56 | + if (empty($host)){ |
|
57 | 57 | return null; |
58 | 58 | } |
59 | 59 | |
60 | 60 | $pattern = $this->config['domain']; |
61 | - if (preg_match("/^(\d{1,3}){4}:\d+$/", $host, $matches)) { |
|
61 | + if (preg_match("/^(\d{1,3}){4}:\d+$/", $host, $matches)){ |
|
62 | 62 | // remove port |
63 | 63 | $host = $matches[1]; |
64 | 64 | } |
65 | 65 | |
66 | - if ($host === 'localhost' || filter_var($host, FILTER_VALIDATE_IP)) { |
|
66 | + if ($host === 'localhost' || filter_var($host, FILTER_VALIDATE_IP)){ |
|
67 | 67 | //We can't use sub-domains when website required by IP |
68 | 68 | $pattern = ltrim($pattern, '.'); |
69 | 69 | } |
70 | 70 | |
71 | - if (strpos($pattern, '%s') === false) { |
|
71 | + if (strpos($pattern, '%s') === false){ |
|
72 | 72 | //Forced domain |
73 | 73 | return $pattern; |
74 | 74 | } |
@@ -53,22 +53,26 @@ |
||
53 | 53 | public function resolveDomain(UriInterface $uri): ?string |
54 | 54 | { |
55 | 55 | $host = $uri->getHost(); |
56 | - if (empty($host)) { |
|
56 | + if (empty($host)) |
|
57 | + { |
|
57 | 58 | return null; |
58 | 59 | } |
59 | 60 | |
60 | 61 | $pattern = $this->config['domain']; |
61 | - if (preg_match("/^(\d{1,3}){4}:\d+$/", $host, $matches)) { |
|
62 | + if (preg_match("/^(\d{1,3}){4}:\d+$/", $host, $matches)) |
|
63 | + { |
|
62 | 64 | // remove port |
63 | 65 | $host = $matches[1]; |
64 | 66 | } |
65 | 67 | |
66 | - if ($host === 'localhost' || filter_var($host, FILTER_VALIDATE_IP)) { |
|
68 | + if ($host === 'localhost' || filter_var($host, FILTER_VALIDATE_IP)) |
|
69 | + { |
|
67 | 70 | //We can't use sub-domains when website required by IP |
68 | 71 | $pattern = ltrim($pattern, '.'); |
69 | 72 | } |
70 | 73 | |
71 | - if (strpos($pattern, '%s') === false) { |
|
74 | + if (strpos($pattern, '%s') === false) |
|
75 | + { |
|
72 | 76 | //Forced domain |
73 | 77 | return $pattern; |
74 | 78 | } |