src/Http/Message/Uri.php
public static function fromArray(array $server)
    {
        $uri = new self('');

        if (isset($server['HTTPS'])) {
            $uri->scheme = $server['HTTPS'] === 'on' ? 'https' : 'http';
        }

        [$host, $port] = Helpers::getHostAndPortFromArray($server);

        $uri->host = \strtolower($host);
        $uri->port = $uri->filterPort($port);

        $path = Helpers::getRequestUri($server);

        $fragment = '';
        if (\strpos($path, '#') !== false) {
            [$path, $fragment] = \explode('#', $path, 2);
        }

        $uri->path = $uri->filterPath(\explode('?', $path, 2)[0]);
        $uri->fragment = $uri->filterFragment($fragment);

        if (isset($server['QUERY_STRING'])) {
            $uri->query = $uri->filterQuery($server['QUERY_STRING']);
        }

        return $uri;
    }
public static function fromArray(array $server)
    {
        $uri = new self('');

        if (isset($server['HTTPS'])) {
            $uri->scheme = $server['HTTPS'] === 'on' ? 'https' : 'http';
        }

        [$host, $port] = Helpers::getHostAndPortFromArray($server);

        $uri->host = \strtolower($host);
        $uri->port = $uri->filterPort($port);

        $path = Helpers::getRequestUri($server);

        $fragment = '';
        if (\strpos($path, '#') !== false) {
            [$path, $fragment] = \explode('#', $path, 2);
        }

        $uri->path = $uri->filterPath(\explode('?', $path, 2)[0]);
        $uri->fragment = $uri->filterFragment($fragment);

        if (isset($server['QUERY_STRING'])) {
            $uri->query = $uri->filterQuery($server['QUERY_STRING']);
        }

        return $uri;
    }
public static function fromArray ( array $ server ) { $ uri = new self ( '' ) ; if ( isset ( $ server [ 'HTTPS' ] ) ) { $ uri -> scheme = $ server [ 'HTTPS' ] === 'on' ? 'https' : 'http' ; } [ $ host , $ port ] = Helpers :: getHostAndPortFromArray ( $ server ) ; $ uri -> host = \ strtolower ( $ host ) ; $ uri -> port = $ uri -> filterPort ( $ port ) ; $ path = Helpers :: getRequestUri ( $ server ) ; $ fragment = '' ; if ( \ strpos ( $ path , '#' ) !== false ) { [ $ path , $ fragment ] = \ explode ( '#' , $ path , 2 ) ; } $ uri -> path = $ uri -> filterPath ( \ explode ( '?' , $ path , 2 ) [ 0 ] ) ; $ uri -> fragment = $ uri -> filterFragment ( $ fragment ) ; if ( isset ( $ server [ 'QUERY_STRING' ] ) ) { $ uri -> query = $ uri -> filterQuery ( $ server [ 'QUERY_STRING' ] ) ; } return $ uri ; }
Get a Uri populated with values from server variables.

@param array $server Typically $_SERVER or similar structure.

@return UriInterface
@throws \InvalidArgumentException
Get a Uri populated with values from server variables .