@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | StreamFactoryInterface $streamFactory, |
69 | 69 | UploadedFileFactory $uploadedFileFactory, |
70 | 70 | UriFactoryInterface $uriFactory |
71 | - ) { |
|
71 | + ){ |
|
72 | 72 | $this->requestFactory = $requestFactory; |
73 | 73 | $this->streamFactory = $streamFactory; |
74 | 74 | $this->uploadedFileFactory = $uploadedFileFactory; |
@@ -115,12 +115,12 @@ discard block |
||
115 | 115 | $uri = $this->getUri($server, $headers); |
116 | 116 | |
117 | 117 | $request = $this->requestFactory->createServerRequest($method, $uri, $server); |
118 | - foreach ($headers as $name => $value) { |
|
118 | + foreach ($headers as $name => $value){ |
|
119 | 119 | $request = $request->withAddedHeader($name, $value); |
120 | 120 | } |
121 | 121 | |
122 | 122 | $protocol = '1.1'; |
123 | - if (!empty($_SERVER['SERVER_PROTOCOL'])) { |
|
123 | + if (!empty($_SERVER['SERVER_PROTOCOL'])){ |
|
124 | 124 | $protocol = str_replace('HTTP/', '', $_SERVER['SERVER_PROTOCOL']); |
125 | 125 | } |
126 | 126 | |
@@ -131,15 +131,15 @@ discard block |
||
131 | 131 | ->withCookieParams($cookies) |
132 | 132 | ->withUploadedFiles($this->getUploadedFilesArray($files)); |
133 | 133 | |
134 | - if ($body === null) { |
|
134 | + if ($body === null){ |
|
135 | 135 | return $request; |
136 | 136 | } |
137 | 137 | |
138 | - if (\is_resource($body)) { |
|
138 | + if (\is_resource($body)){ |
|
139 | 139 | $body = $this->streamFactory->createStreamFromResource($body); |
140 | - } elseif (\is_string($body)) { |
|
140 | + } elseif (\is_string($body)){ |
|
141 | 141 | $body = $this->streamFactory->createStream($body); |
142 | - } elseif (!$body instanceof StreamInterface) { |
|
142 | + } elseif (!$body instanceof StreamInterface){ |
|
143 | 143 | throw new \InvalidArgumentException('Body parameter for ServerRequestFactory::createFromParameters() must be instance of StreamInterface, resource or null.'); |
144 | 144 | } |
145 | 145 | |
@@ -154,29 +154,29 @@ discard block |
||
154 | 154 | private function getUri(array $server, array $headers): UriInterface |
155 | 155 | { |
156 | 156 | $uri = $this->uriFactory->createUri(); |
157 | - if (isset($server['HTTPS'])) { |
|
157 | + if (isset($server['HTTPS'])){ |
|
158 | 158 | $uri = $uri->withScheme($server['HTTPS'] === 'on' ? 'https' : 'http'); |
159 | 159 | } |
160 | 160 | |
161 | - if (isset($server['HTTP_HOST'])) { |
|
162 | - if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches)) { |
|
161 | + if (isset($server['HTTP_HOST'])){ |
|
162 | + if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches)){ |
|
163 | 163 | $uri = $uri->withHost($matches[1])->withPort($matches[2]); |
164 | - } else { |
|
164 | + }else{ |
|
165 | 165 | $uri = $uri->withHost($server['HTTP_HOST']); |
166 | 166 | } |
167 | - } elseif (isset($server['SERVER_NAME'])) { |
|
167 | + } elseif (isset($server['SERVER_NAME'])){ |
|
168 | 168 | $uri = $uri->withHost($server['SERVER_NAME']); |
169 | 169 | } |
170 | 170 | |
171 | - if (isset($server['SERVER_PORT'])) { |
|
171 | + if (isset($server['SERVER_PORT'])){ |
|
172 | 172 | $uri = $uri->withPort($server['SERVER_PORT']); |
173 | 173 | } |
174 | 174 | |
175 | - if (isset($server['REQUEST_URI'])) { |
|
175 | + if (isset($server['REQUEST_URI'])){ |
|
176 | 176 | $uri = $uri->withPath(\explode('?', $server['REQUEST_URI'])[0]); |
177 | 177 | } |
178 | 178 | |
179 | - if (isset($server['QUERY_STRING'])) { |
|
179 | + if (isset($server['QUERY_STRING'])){ |
|
180 | 180 | $uri = $uri->withQuery($server['QUERY_STRING']); |
181 | 181 | } |
182 | 182 | |
@@ -188,12 +188,12 @@ discard block |
||
188 | 188 | */ |
189 | 189 | private static function getHeadersFromGlobals(): array |
190 | 190 | { |
191 | - if (\function_exists('getallheaders')) { |
|
191 | + if (\function_exists('getallheaders')){ |
|
192 | 192 | $headers = getallheaders(); |
193 | - } else { |
|
193 | + }else{ |
|
194 | 194 | $headers = []; |
195 | - foreach ($_SERVER as $name => $value) { |
|
196 | - if (strncmp($name, 'HTTP_', 5) === 0) { |
|
195 | + foreach ($_SERVER as $name => $value){ |
|
196 | + if (strncmp($name, 'HTTP_', 5) === 0){ |
|
197 | 197 | $name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5))))); |
198 | 198 | $headers[$name] = $value; |
199 | 199 | } |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | private function getUploadedFilesArray(array $filesArray): array |
211 | 211 | { |
212 | 212 | $files = []; |
213 | - foreach ($filesArray as $class => $info) { |
|
213 | + foreach ($filesArray as $class => $info){ |
|
214 | 214 | $files[$class] = []; |
215 | 215 | $this->populateUploadedFileRecursive( |
216 | 216 | $files[$class], |
@@ -238,8 +238,8 @@ discard block |
||
238 | 238 | */ |
239 | 239 | private function populateUploadedFileRecursive(&$files, $names, $tempNames, $types, $sizes, $errors): void |
240 | 240 | { |
241 | - if (\is_array($names)) { |
|
242 | - foreach ($names as $i => $name) { |
|
241 | + if (\is_array($names)){ |
|
242 | + foreach ($names as $i => $name){ |
|
243 | 243 | $files[$i] = []; |
244 | 244 | $this->populateUploadedFileRecursive( |
245 | 245 | $files[$i], |
@@ -250,10 +250,10 @@ discard block |
||
250 | 250 | $errors[$i] |
251 | 251 | ); |
252 | 252 | } |
253 | - } else { |
|
254 | - try { |
|
253 | + }else{ |
|
254 | + try{ |
|
255 | 255 | $stream = $this->streamFactory->createStreamFromFile($tempNames); |
256 | - } catch (\RuntimeException $e) { |
|
256 | + }catch (\RuntimeException $e){ |
|
257 | 257 | $stream = $this->streamFactory->createStream(); |
258 | 258 | } |
259 | 259 |
@@ -115,12 +115,14 @@ discard block |
||
115 | 115 | $uri = $this->getUri($server, $headers); |
116 | 116 | |
117 | 117 | $request = $this->requestFactory->createServerRequest($method, $uri, $server); |
118 | - foreach ($headers as $name => $value) { |
|
118 | + foreach ($headers as $name => $value) |
|
119 | + { |
|
119 | 120 | $request = $request->withAddedHeader($name, $value); |
120 | 121 | } |
121 | 122 | |
122 | 123 | $protocol = '1.1'; |
123 | - if (!empty($_SERVER['SERVER_PROTOCOL'])) { |
|
124 | + if (!empty($_SERVER['SERVER_PROTOCOL'])) |
|
125 | + { |
|
124 | 126 | $protocol = str_replace('HTTP/', '', $_SERVER['SERVER_PROTOCOL']); |
125 | 127 | } |
126 | 128 | |
@@ -131,15 +133,21 @@ discard block |
||
131 | 133 | ->withCookieParams($cookies) |
132 | 134 | ->withUploadedFiles($this->getUploadedFilesArray($files)); |
133 | 135 | |
134 | - if ($body === null) { |
|
136 | + if ($body === null) |
|
137 | + { |
|
135 | 138 | return $request; |
136 | 139 | } |
137 | 140 | |
138 | - if (\is_resource($body)) { |
|
141 | + if (\is_resource($body)) |
|
142 | + { |
|
139 | 143 | $body = $this->streamFactory->createStreamFromResource($body); |
140 | - } elseif (\is_string($body)) { |
|
144 | + } |
|
145 | + elseif (\is_string($body)) |
|
146 | + { |
|
141 | 147 | $body = $this->streamFactory->createStream($body); |
142 | - } elseif (!$body instanceof StreamInterface) { |
|
148 | + } |
|
149 | + elseif (!$body instanceof StreamInterface) |
|
150 | + { |
|
143 | 151 | throw new \InvalidArgumentException('Body parameter for ServerRequestFactory::createFromParameters() must be instance of StreamInterface, resource or null.'); |
144 | 152 | } |
145 | 153 | |
@@ -154,29 +162,39 @@ discard block |
||
154 | 162 | private function getUri(array $server, array $headers): UriInterface |
155 | 163 | { |
156 | 164 | $uri = $this->uriFactory->createUri(); |
157 | - if (isset($server['HTTPS'])) { |
|
165 | + if (isset($server['HTTPS'])) |
|
166 | + { |
|
158 | 167 | $uri = $uri->withScheme($server['HTTPS'] === 'on' ? 'https' : 'http'); |
159 | 168 | } |
160 | 169 | |
161 | - if (isset($server['HTTP_HOST'])) { |
|
162 | - if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches)) { |
|
170 | + if (isset($server['HTTP_HOST'])) |
|
171 | + { |
|
172 | + if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches)) |
|
173 | + { |
|
163 | 174 | $uri = $uri->withHost($matches[1])->withPort($matches[2]); |
164 | - } else { |
|
175 | + } |
|
176 | + else |
|
177 | + { |
|
165 | 178 | $uri = $uri->withHost($server['HTTP_HOST']); |
166 | 179 | } |
167 | - } elseif (isset($server['SERVER_NAME'])) { |
|
180 | + } |
|
181 | + elseif (isset($server['SERVER_NAME'])) |
|
182 | + { |
|
168 | 183 | $uri = $uri->withHost($server['SERVER_NAME']); |
169 | 184 | } |
170 | 185 | |
171 | - if (isset($server['SERVER_PORT'])) { |
|
186 | + if (isset($server['SERVER_PORT'])) |
|
187 | + { |
|
172 | 188 | $uri = $uri->withPort($server['SERVER_PORT']); |
173 | 189 | } |
174 | 190 | |
175 | - if (isset($server['REQUEST_URI'])) { |
|
191 | + if (isset($server['REQUEST_URI'])) |
|
192 | + { |
|
176 | 193 | $uri = $uri->withPath(\explode('?', $server['REQUEST_URI'])[0]); |
177 | 194 | } |
178 | 195 | |
179 | - if (isset($server['QUERY_STRING'])) { |
|
196 | + if (isset($server['QUERY_STRING'])) |
|
197 | + { |
|
180 | 198 | $uri = $uri->withQuery($server['QUERY_STRING']); |
181 | 199 | } |
182 | 200 | |
@@ -188,12 +206,17 @@ discard block |
||
188 | 206 | */ |
189 | 207 | private static function getHeadersFromGlobals(): array |
190 | 208 | { |
191 | - if (\function_exists('getallheaders')) { |
|
209 | + if (\function_exists('getallheaders')) |
|
210 | + { |
|
192 | 211 | $headers = getallheaders(); |
193 | - } else { |
|
212 | + } |
|
213 | + else |
|
214 | + { |
|
194 | 215 | $headers = []; |
195 | - foreach ($_SERVER as $name => $value) { |
|
196 | - if (strncmp($name, 'HTTP_', 5) === 0) { |
|
216 | + foreach ($_SERVER as $name => $value) |
|
217 | + { |
|
218 | + if (strncmp($name, 'HTTP_', 5) === 0) |
|
219 | + { |
|
197 | 220 | $name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5))))); |
198 | 221 | $headers[$name] = $value; |
199 | 222 | } |
@@ -210,7 +233,8 @@ discard block |
||
210 | 233 | private function getUploadedFilesArray(array $filesArray): array |
211 | 234 | { |
212 | 235 | $files = []; |
213 | - foreach ($filesArray as $class => $info) { |
|
236 | + foreach ($filesArray as $class => $info) |
|
237 | + { |
|
214 | 238 | $files[$class] = []; |
215 | 239 | $this->populateUploadedFileRecursive( |
216 | 240 | $files[$class], |
@@ -238,8 +262,10 @@ discard block |
||
238 | 262 | */ |
239 | 263 | private function populateUploadedFileRecursive(&$files, $names, $tempNames, $types, $sizes, $errors): void |
240 | 264 | { |
241 | - if (\is_array($names)) { |
|
242 | - foreach ($names as $i => $name) { |
|
265 | + if (\is_array($names)) |
|
266 | + { |
|
267 | + foreach ($names as $i => $name) |
|
268 | + { |
|
243 | 269 | $files[$i] = []; |
244 | 270 | $this->populateUploadedFileRecursive( |
245 | 271 | $files[$i], |
@@ -250,10 +276,15 @@ discard block |
||
250 | 276 | $errors[$i] |
251 | 277 | ); |
252 | 278 | } |
253 | - } else { |
|
254 | - try { |
|
279 | + } |
|
280 | + else |
|
281 | + { |
|
282 | + try |
|
283 | + { |
|
255 | 284 | $stream = $this->streamFactory->createStreamFromFile($tempNames); |
256 | - } catch (\RuntimeException $e) { |
|
285 | + } |
|
286 | + catch (\RuntimeException $e) |
|
287 | + { |
|
257 | 288 | $stream = $this->streamFactory->createStream(); |
258 | 289 | } |
259 | 290 |
@@ -38,7 +38,7 @@ |
||
38 | 38 | $response = new Response('php://memory', $code, []); |
39 | 39 | $response = $response->withStatus($code, $reasonPhrase); |
40 | 40 | |
41 | - foreach ($this->config->baseHeaders() as $header => $value) { |
|
41 | + foreach ($this->config->baseHeaders() as $header => $value){ |
|
42 | 42 | $response = $response->withAddedHeader($header, $value); |
43 | 43 | } |
44 | 44 |
@@ -38,7 +38,8 @@ |
||
38 | 38 | $response = new Response('php://memory', $code, []); |
39 | 39 | $response = $response->withStatus($code, $reasonPhrase); |
40 | 40 | |
41 | - foreach ($this->config->baseHeaders() as $header => $value) { |
|
41 | + foreach ($this->config->baseHeaders() as $header => $value) |
|
42 | + { |
|
42 | 43 | $response = $response->withAddedHeader($header, $value); |
43 | 44 | } |
44 | 45 |
@@ -26,7 +26,7 @@ |
||
26 | 26 | string $clientFilename = null, |
27 | 27 | string $clientMediaType = null |
28 | 28 | ): UploadedFileInterface { |
29 | - if ($size === null) { |
|
29 | + if ($size === null){ |
|
30 | 30 | $size = $stream->getSize(); |
31 | 31 | } |
32 | 32 |
@@ -26,7 +26,8 @@ |
||
26 | 26 | string $clientFilename = null, |
27 | 27 | string $clientMediaType = null |
28 | 28 | ): UploadedFileInterface { |
29 | - if ($size === null) { |
|
29 | + if ($size === null) |
|
30 | + { |
|
30 | 31 | $size = $stream->getSize(); |
31 | 32 | } |
32 | 33 |
@@ -65,11 +65,11 @@ discard block |
||
65 | 65 | */ |
66 | 66 | private function assertNoPreviousOutput() |
67 | 67 | { |
68 | - if (headers_sent()) { |
|
68 | + if (headers_sent()){ |
|
69 | 69 | throw new EmitterException("Unable to emit response, headers already send."); |
70 | 70 | } |
71 | 71 | |
72 | - if (ob_get_level() > 0 && ob_get_length() > 0) { |
|
72 | + if (ob_get_level() > 0 && ob_get_length() > 0){ |
|
73 | 73 | throw new EmitterException("Unable to emit response, found non closed buffered output."); |
74 | 74 | } |
75 | 75 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | 'HTTP/%s %d%s', |
96 | 96 | $response->getProtocolVersion(), |
97 | 97 | $statusCode, |
98 | - ($reasonPhrase ? ' ' . $reasonPhrase : '') |
|
98 | + ($reasonPhrase ? ' '.$reasonPhrase : '') |
|
99 | 99 | ), true, $statusCode); |
100 | 100 | } |
101 | 101 | |
@@ -113,10 +113,10 @@ discard block |
||
113 | 113 | { |
114 | 114 | $statusCode = $response->getStatusCode(); |
115 | 115 | |
116 | - foreach ($response->getHeaders() as $header => $values) { |
|
116 | + foreach ($response->getHeaders() as $header => $values){ |
|
117 | 117 | $name = $this->filterHeader($header); |
118 | 118 | $first = $name === 'Set-Cookie' ? false : true; |
119 | - foreach ($values as $value) { |
|
119 | + foreach ($values as $value){ |
|
120 | 120 | header(sprintf( |
121 | 121 | '%s: %s', |
122 | 122 | $name, |
@@ -65,11 +65,13 @@ discard block |
||
65 | 65 | */ |
66 | 66 | private function assertNoPreviousOutput() |
67 | 67 | { |
68 | - if (headers_sent()) { |
|
68 | + if (headers_sent()) |
|
69 | + { |
|
69 | 70 | throw new EmitterException("Unable to emit response, headers already send."); |
70 | 71 | } |
71 | 72 | |
72 | - if (ob_get_level() > 0 && ob_get_length() > 0) { |
|
73 | + if (ob_get_level() > 0 && ob_get_length() > 0) |
|
74 | + { |
|
73 | 75 | throw new EmitterException("Unable to emit response, found non closed buffered output."); |
74 | 76 | } |
75 | 77 | } |
@@ -113,10 +115,12 @@ discard block |
||
113 | 115 | { |
114 | 116 | $statusCode = $response->getStatusCode(); |
115 | 117 | |
116 | - foreach ($response->getHeaders() as $header => $values) { |
|
118 | + foreach ($response->getHeaders() as $header => $values) |
|
119 | + { |
|
117 | 120 | $name = $this->filterHeader($header); |
118 | 121 | $first = $name === 'Set-Cookie' ? false : true; |
119 | - foreach ($values as $value) { |
|
122 | + foreach ($values as $value) |
|
123 | + { |
|
120 | 124 | header(sprintf( |
121 | 125 | '%s: %s', |
122 | 126 | $name, |