function ServerRequestCreator::createUriFromArray
Create a new uri from server variable.
Parameters
array $server typically $_SERVER or similar structure:
1 call to ServerRequestCreator::createUriFromArray()
- ServerRequestCreator::getUriFromEnvWithHTTP in vendor/
nyholm/ psr7-server/ src/ ServerRequestCreator.php
File
-
vendor/
nyholm/ psr7-server/ src/ ServerRequestCreator.php, line 265
Class
- ServerRequestCreator
- @author Tobias Nyholm <tobias.nyholm@gmail.com> @author Martijn van der Ven <martijn@vanderven.se>
Namespace
Nyholm\Psr7ServerCode
private function createUriFromArray(array $server) : UriInterface {
$uri = $this->uriFactory
->createUri('');
if (isset($server['HTTP_X_FORWARDED_PROTO'])) {
$uri = $uri->withScheme($server['HTTP_X_FORWARDED_PROTO']);
}
else {
if (isset($server['REQUEST_SCHEME'])) {
$uri = $uri->withScheme($server['REQUEST_SCHEME']);
}
elseif (isset($server['HTTPS'])) {
$uri = $uri->withScheme('on' === $server['HTTPS'] ? 'https' : 'http');
}
if (isset($server['SERVER_PORT'])) {
$uri = $uri->withPort($server['SERVER_PORT']);
}
}
if (isset($server['HTTP_HOST'])) {
if (1 === \preg_match('/^(.+)\\:(\\d+)$/', $server['HTTP_HOST'], $matches)) {
$uri = $uri->withHost($matches[1])
->withPort($matches[2]);
}
else {
$uri = $uri->withHost($server['HTTP_HOST']);
}
}
elseif (isset($server['SERVER_NAME'])) {
$uri = $uri->withHost($server['SERVER_NAME']);
}
if (isset($server['REQUEST_URI'])) {
$uri = $uri->withPath(\current(\explode('?', $server['REQUEST_URI'])));
}
if (isset($server['QUERY_STRING'])) {
$uri = $uri->withQuery($server['QUERY_STRING']);
}
return $uri;
}