Get a Uri populated with values from server variables.

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

@return UriInterface
@throws \InvalidArgumentException
177423
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;
    }
1209351
public static function prepareUri(array $server, array $headers)
    {
        $uri = new PsrUri('');

        // URI scheme
        $scheme = 'http';
        $https = ServerHelper::getValue($server, 'HTTPS');

        // Is https or not
        if (($https && $https !== 'off') || HeaderHelper::getValue($headers, 'x-forwarded-proto', false) === 'https') {
            $scheme = 'https';
        }

        // URI host
        $host = '';
        $port = null;

        static::getHostAndPortFromHeaders($host, $port, $server, $headers);

        // URI path
        $path = static::getRequestUri($server);
        $path = static::stripQueryString($path);

        // URI query
        $query = '';

        if (isset($server['QUERY_STRING'])) {
            $query = ltrim($server['QUERY_STRING'], '?');
        }

        // URI fragment
        $fragment = '';

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

        return $uri->withScheme($scheme)
            ->withHost($host)
            ->withPort($port)
            ->withPath($path)
            ->withFragment($fragment)
            ->withQuery($query);
    }
278580
protected static function getWebhooksURL($server)
    {
        if ($server === static::USE_PRODUCTION_SERVER) {
            $url = 'https://api.authorize.net/rest/v1/';
        } else if ($server === static::USE_DEVELOPMENT_SERVER) {
            $url = 'https://apitest.authorize.net/rest/v1/';
        } else {
            throw new AuthnetInvalidServerException('You did not provide a valid server.');
        }
        return $url;
    }
982983
private static function parseUrl(array $serverVars): UrlInterface
    {
        $uriAndQueryString = explode('?', self::fixRequestUri($serverVars['REQUEST_URI']), 2);
        $hostAndPort = explode(':', $serverVars['HTTP_HOST'], 2);

        return Url::fromParts(
            Scheme::parse('http' . (isset($serverVars['HTTPS']) && $serverVars['HTTPS'] !== '' && $serverVars['HTTPS'] !== 'off' ? 's' : '')),
            Host::parse($hostAndPort[0]),
            count($hostAndPort) > 1 ? intval($hostAndPort[1]) : null,
            UrlPath::parse($uriAndQueryString[0]),
            count($uriAndQueryString) > 1 ? $uriAndQueryString[1] : null
        );
    }
1311594
private function getPathFromUri($uri)
    {
        $uriParser = new UriParser($uri);
        // Prepare uri
        $uriParser->encode();
        $uri = $uriParser->stripFragment();
        if (strpos($uri, '/') === 0) {
            // URI is already an path
            return $uri;
        }
        if (!$uriParser->validate()) {
            throw new \InvalidArgumentException('Invalid URI');
        }
        $path = (($path = parse_url($uri, PHP_URL_PATH)) === null) ? '/' : $path;
        $query = (($query = parse_url($uri, PHP_URL_QUERY)) === null) ? '' : '?' . $query;
        return $path . $query;
    }
1229886
private function withScheme(UriInterface $uri, array $server) : UriInterface {
		if (isset($server['HTTPS'])) {
			return $uri->withScheme($server['HTTPS'] == 'on' ? 'https' : 'http');
		}

		return $uri->withScheme('http');
	}
9861
private static function getProtocolVersion(array $server)
    {
        if (!isset($server['SERVER_PROTOCOL'])) {
            return '1.1';
        }

        if (!preg_match('/^(HTTP\/)?(\d+(?:\.\d+)+)/', $server['SERVER_PROTOCOL'], $matches)) {
            throw new \UnexpectedValueException(
                sprintf(
                    'Invalid protocol version format (%s)',
                    $server['SERVER_PROTOCOL']
                )
            );
        }

        return $matches[2];
    }
234667
public function sapiUri($server = null)
    {
        return new Messages\URI\SAPI(
            $server !== null ? $server : $_SERVER
        );
    }
333493
public static function retrieve(array $server = null)
    {
        if (empty($server)) {
            $server = $_SERVER;
        }

        $port = '80';

        if (isset($server['SERVER_PORT'])) {
            $port = $server['SERVER_PORT'];
        }

        return (int) $port;
    }
909905
def __get_uri(self, server):
        """"""
        # Select the connection mode (with or without password)
        if server['password'] != "":
            if server['status'] == 'PROTECTED':
                # Try with the preconfigure password (only if status is PROTECTED)
                clear_password = self.password.get_password(server['name'])
                if clear_password is not None:
                    server['password'] = self.password.sha256_hash(clear_password)
            return 'http://{}:{}@{}:{}'.format(server['username'], server['password'],
                                               server['ip'], server['port'])
        else:
            return 'http://{}:{}'.format(server['ip'], server['port'])
879617
public function parseRequest(array $server, IHttpRequest $request = null) {
        if ( ! $request instanceof IHttpRequest) {
            $request = $this->createRequest();
        }

        $this->setMethod($request, $server);
        $this->setUrl($request, $server);
        $this->setHeaders($request, $server);
        $this->setProtocol($request, $server);
        $this->setContent($request);
        $this->setServerGlobal($request, $server);

        return $request;
    }
803409
public function fetchUriString($server = null)
    {
        $server || $server = $this->_SERVER;

        // Fetch request string (apache)
        $uri = $server['REQUEST_URI'];
        $uri = parse_url($uri)['path'];

        // Further cleaning of the uri
        $uri = str_replace(array('//', '../'), '/', trim($uri, '/'));

        if (php_sapi_name() != 'cli' && !defined('STDIN')) {

            $dirname = dirname($server['SCRIPT_FILENAME']);
            $dirname !== '.' || $dirname = '';

            $diff = str_replace($server['DOCUMENT_ROOT'], '', $dirname);

            $this->setBaseUri($diff);

            $uri = trim(str_replace($diff, '', '/' . $uri), '/');
        }

        return empty($uri) ? '/' : $uri;
    }
764980
public function createUriFromServer(array $server): UriInterface
        {
            // scheme, host, post, user, pass
            $scheme = (empty($server['HTTPS']) || $server['HTTPS'] === 'off') ? 'http' : 'https';
            $host   = (isset($server['HTTP_HOST'])) ? $server['HTTP_HOST'] : $server['SERVER_NAME'];
            $port   = (isset($server['SERVER_PORT'])) ? (int) $server['SERVER_PORT'] : 80;
            $user   = (isset($server['PHP_AUTH_USER'])) ? $server['PHP_AUTH_USER'] : '';
            $pass   = (isset($server['PHP_AUTH_PW'])) ? $server['PHP_AUTH_PW'] : '';
            
            // path
            $path = parse_url('http://example.com' . $server['REQUEST_URI'], PHP_URL_PATH);
            $path = rawurldecode($path);

            // query
            $query = (isset($server['QUERY_STRING'])) ? $server['QUERY_STRING'] : '';

            // fragment (not available in $_SERVER)
            $fragment = '';

            $uri = new Uri('');
            $uri = $uri->withScheme($scheme);
            $uri = $uri->withHost($host);
            $uri = $uri->withPort($port);
            $uri = $uri->withUserInfo($user, $pass);
            $uri = $uri->withPath($path);
            $uri = $uri->withQuery($query);
            $uri = $uri->withFragment($fragment);
            return $uri;
        }
332534
private function getRequestUri(ServerRequestInterface $request) : string
    {
        $uri = $request->getUri()->getPath();
        $query = $request->getUri()->getQuery();

        if (!empty($query)) {
            return $uri . '?' . \urldecode($query);
        }

        return $uri;
    }
452518
public function getValue(ServerRequestInterface $request, $argument = null)
    {
        $url = $request->getUri();
        $return = $url->getPath();
        if ($url->getQuery()) {
            $return .= '?' . $url->getQuery();
        }
        if ($url->getFragment()) {
            $return .= '#' . $url->getFragment();
        }

        return $return;
    }
1058023
public function getServer($server)
    {
        if (! array_key_exists($server, $this->servers)) {
            throw new \Exception('Server ['.$server.'] is not defined.');
        }

        return Arr::get($this->servers, $server);
    }
1374389
private function createUri(HTTPServerFactory $httpFactory, array $server) : UriInterface {
		$uri = $httpFactory->createUri();

		$uri = $this->withScheme($uri, $server);
		$uri = $this->withHost($uri, $server);
		$uri = $this->withServerPort($uri, $server);
		$uri = $this->withPath($uri, $server);
		$uri = $this->withQueryString($uri, $server);

		return $uri;
	}