Mercurial > hg > isophonics-drupal-site
comparison vendor/guzzlehttp/psr7/src/ServerRequest.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
164 * @return ServerRequestInterface | 164 * @return ServerRequestInterface |
165 */ | 165 */ |
166 public static function fromGlobals() | 166 public static function fromGlobals() |
167 { | 167 { |
168 $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET'; | 168 $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET'; |
169 $headers = function_exists('getallheaders') ? getallheaders() : []; | 169 $headers = getallheaders(); |
170 $uri = self::getUriFromGlobals(); | 170 $uri = self::getUriFromGlobals(); |
171 $body = new LazyOpenStream('php://input', 'r+'); | 171 $body = new LazyOpenStream('php://input', 'r+'); |
172 $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? str_replace('HTTP/', '', $_SERVER['SERVER_PROTOCOL']) : '1.1'; | 172 $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? str_replace('HTTP/', '', $_SERVER['SERVER_PROTOCOL']) : '1.1'; |
173 | 173 |
174 $serverRequest = new ServerRequest($method, $uri, $headers, $body, $protocol, $_SERVER); | 174 $serverRequest = new ServerRequest($method, $uri, $headers, $body, $protocol, $_SERVER); |
178 ->withQueryParams($_GET) | 178 ->withQueryParams($_GET) |
179 ->withParsedBody($_POST) | 179 ->withParsedBody($_POST) |
180 ->withUploadedFiles(self::normalizeFiles($_FILES)); | 180 ->withUploadedFiles(self::normalizeFiles($_FILES)); |
181 } | 181 } |
182 | 182 |
183 private static function extractHostAndPortFromAuthority($authority) | |
184 { | |
185 $uri = 'http://'.$authority; | |
186 $parts = parse_url($uri); | |
187 if (false === $parts) { | |
188 return [null, null]; | |
189 } | |
190 | |
191 $host = isset($parts['host']) ? $parts['host'] : null; | |
192 $port = isset($parts['port']) ? $parts['port'] : null; | |
193 | |
194 return [$host, $port]; | |
195 } | |
196 | |
183 /** | 197 /** |
184 * Get a Uri populated with values from $_SERVER. | 198 * Get a Uri populated with values from $_SERVER. |
185 * | 199 * |
186 * @return UriInterface | 200 * @return UriInterface |
187 */ | 201 */ |
188 public static function getUriFromGlobals() { | 202 public static function getUriFromGlobals() |
203 { | |
189 $uri = new Uri(''); | 204 $uri = new Uri(''); |
190 | 205 |
191 $uri = $uri->withScheme(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http'); | 206 $uri = $uri->withScheme(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http'); |
192 | 207 |
193 $hasPort = false; | 208 $hasPort = false; |
194 if (isset($_SERVER['HTTP_HOST'])) { | 209 if (isset($_SERVER['HTTP_HOST'])) { |
195 $hostHeaderParts = explode(':', $_SERVER['HTTP_HOST']); | 210 list($host, $port) = self::extractHostAndPortFromAuthority($_SERVER['HTTP_HOST']); |
196 $uri = $uri->withHost($hostHeaderParts[0]); | 211 if ($host !== null) { |
197 if (isset($hostHeaderParts[1])) { | 212 $uri = $uri->withHost($host); |
213 } | |
214 | |
215 if ($port !== null) { | |
198 $hasPort = true; | 216 $hasPort = true; |
199 $uri = $uri->withPort($hostHeaderParts[1]); | 217 $uri = $uri->withPort($port); |
200 } | 218 } |
201 } elseif (isset($_SERVER['SERVER_NAME'])) { | 219 } elseif (isset($_SERVER['SERVER_NAME'])) { |
202 $uri = $uri->withHost($_SERVER['SERVER_NAME']); | 220 $uri = $uri->withHost($_SERVER['SERVER_NAME']); |
203 } elseif (isset($_SERVER['SERVER_ADDR'])) { | 221 } elseif (isset($_SERVER['SERVER_ADDR'])) { |
204 $uri = $uri->withHost($_SERVER['SERVER_ADDR']); | 222 $uri = $uri->withHost($_SERVER['SERVER_ADDR']); |
208 $uri = $uri->withPort($_SERVER['SERVER_PORT']); | 226 $uri = $uri->withPort($_SERVER['SERVER_PORT']); |
209 } | 227 } |
210 | 228 |
211 $hasQuery = false; | 229 $hasQuery = false; |
212 if (isset($_SERVER['REQUEST_URI'])) { | 230 if (isset($_SERVER['REQUEST_URI'])) { |
213 $requestUriParts = explode('?', $_SERVER['REQUEST_URI']); | 231 $requestUriParts = explode('?', $_SERVER['REQUEST_URI'], 2); |
214 $uri = $uri->withPath($requestUriParts[0]); | 232 $uri = $uri->withPath($requestUriParts[0]); |
215 if (isset($requestUriParts[1])) { | 233 if (isset($requestUriParts[1])) { |
216 $hasQuery = true; | 234 $hasQuery = true; |
217 $uri = $uri->withQuery($requestUriParts[1]); | 235 $uri = $uri->withQuery($requestUriParts[1]); |
218 } | 236 } |