public static function marshalUriFromServer(array $server, array $headers)
{
$uri = new Uri('');
// URI scheme
$scheme = 'http';
$https = self::get('HTTPS', $server);
if ($https && 'off' !== $https || self::getHeader('x-forwarded-proto', $headers, false) === 'https') {
$scheme = 'https';
}
if (!empty($scheme)) {
$uri = $uri->withScheme($scheme);
}
// Set the host
$accumulator = (object) ['host' => '', 'port' => null];
self::marshalHostAndPortFromHeaders($accumulator, $server, $headers);
$host = $accumulator->host;
$port = $accumulator->port;
if (!empty($host)) {
$uri = $uri->withHost($host);
if (!empty($port)) {
$uri = $uri->withPort($port);
}
}
// URI path
$path = self::marshalRequestUri($server);
$path = self::stripQueryString($path);
// URI query
$query = '';
if (isset($server['QUERY_STRING'])) {
$query = ltrim($server['QUERY_STRING'], '?');
}
return $uri->withPath($path)->withQuery($query);
}