Creates new Uri from array.

@param array $server
@return UriInterface
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;
        }
466524
private static function fetchScheme(array $server): string
    {
        $server += ['HTTPS' => ''];
        $res = filter_var($server['HTTPS'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);

        return $res !== false ? 'https' : 'http';
    }
496439
private function withHost(UriInterface $uri, array $server) : UriInterface {
		if (isset($server['HTTP_HOST'])) {
			$server['HTTP_HOST'] = preg_replace('/:[0-9]+$/', '', $server['HTTP_HOST']);
			return $uri->withHost($server['HTTP_HOST']);
		} elseif (isset($server['SERVER_NAME'])) {
			return $uri->withHost($server['SERVER_NAME']);
		}

		return $uri;
	}
457849
public static function marshalHeaders(array $server)
    {
        $headers = array();
        foreach ($server as $key => $value) {
            if (strpos($key, 'HTTP_COOKIE') === 0) {
                // Cookies are handled using the $_COOKIE superglobal
                continue;
            }

            if ($value && strpos($key, 'HTTP_') === 0) {
                $name = strtr(substr($key, 5), '_', ' ');
                $name = strtr(ucwords(strtolower($name)), ' ', '-');
                $name = strtolower($name);

                $headers[$name] = $value;
                continue;
            }

            if ($value && strpos($key, 'CONTENT_') === 0) {
                $name = substr($key, 8); // Content-
                $name = 'Content-' . (($name == 'MD5') ? $name : ucfirst(strtolower($name)));
                $name = strtolower($name);
                $headers[$name] = $value;
                continue;
            }
        }

        return $headers;
    }
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);
    }
615284
public static function createServerRequest($method, $uri)
    {
        if (! static::$serverRequestFactory) {
            static::$serverRequestFactory = new ServerRequestFactory();
        }

        return static::$serverRequestFactory->createServerRequest($method, $uri);
    }
1371473
private function determineHeader(array $server): MapInterface
    {
        $header = new Map();

        foreach ($server as $name => $value) {
            if (strpos($name, 'HTTP_') === 0) {
                $name = substr($name, 5);
                $name = explode('_', $name);
                $name = array_map('strtolower', $name);
                $name = array_map('ucfirst', $name);
                $name = implode('-', $name);

                $header->set($name, $value);
            }
        }

        return new ReadOnlyMap($header);
    }
1312016
public static function make(array $server = null)
    {
        if (empty($server)) {
            $server = $_SERVER;
        }

        if (isset($server['REQUEST_URI'])) {
            return parse_url($server['REQUEST_URI'], PHP_URL_PATH);
        }
    }
6284
public static function getHeadersFromServer(array $server): array
    {
        $headers = [];
        foreach ($server as $key => $value) {
            // Apache prefixes environment variables with REDIRECT_
            // if they are added by rewrite rules
            if (0 === \strpos($key, 'REDIRECT_')) {
                $key = \substr($key, 9);

                // We will not overwrite existing variables with the
                // prefixed versions, though
                if (\array_key_exists($key, $server)) {
                    continue;
                }
            }

            if ($value && 0 === \strpos($key, 'HTTP_')) {
                $name = \strtr(\strtolower(\substr($key, 5)), '_', '-');
                $headers[$name] = $value;

                continue;
            }

            if ($value && 0 === \strpos($key, 'CONTENT_')) {
                $name = 'content-'.\strtolower(\substr($key, 8));
                $headers[$name] = $value;

                continue;
            }
        }

        return $headers;
    }
1160861
public static function createServerRequestFromGlobals()
    {
        $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
        $headers = function_exists('getallheaders') ? getallheaders() : [];

        foreach ($headers as $name => $value) {
            unset($headers[$name]);
            $name = str_replace('-', '_', $name);
            $headers[$name] = $value;
        }

        return new static($method, static::createUriFromGlobal($_SERVER), $headers, new PhpInputStream(), $_SERVER);
    }
498803
public function create($uri, $method = 'GET', $params = [], $cookie = [], $files = [], $server = [], $content = null)
    {
        $server['PATH_INFO']      = '';
        $server['REQUEST_METHOD'] = strtoupper($method);
        $info                     = parse_url($uri);
        if (isset($info['host'])) {
            $server['SERVER_NAME'] = $info['host'];
            $server['HTTP_HOST']   = $info['host'];
        }
        if (isset($info['scheme'])) {
            if ('https' === $info['scheme']) {
                $server['HTTPS']       = 'on';
                $server['SERVER_PORT'] = 443;
            } else {
                unset($server['HTTPS']);
                $server['SERVER_PORT'] = 80;
            }
        }
        if (isset($info['port'])) {
            $server['SERVER_PORT'] = $info['port'];
            $server['HTTP_HOST']   = $server['HTTP_HOST'] . ':' . $info['port'];
        }
        if (isset($info['user'])) {
            $server['PHP_AUTH_USER'] = $info['user'];
        }
        if (isset($info['pass'])) {
            $server['PHP_AUTH_PW'] = $info['pass'];
        }
        if (!isset($info['path'])) {
            $info['path'] = '/';
        }
        $options                      = [];
        $options[strtolower($method)] = $params;
        $queryString                  = '';
        if (isset($info['query'])) {
            parse_str(html_entity_decode($info['query']), $query);
            if (!empty($params)) {
                $params      = array_replace($query, $params);
                $queryString = http_build_query($query, '', '&');
            } else {
                $params      = $query;
                $queryString = $info['query'];
            }
        } elseif (!empty($params)) {
            $queryString = http_build_query($params, '', '&');
        }
        if ($queryString) {
            parse_str($queryString, $get);
            $options['get'] = isset($options['get']) ? array_merge($get, $options['get']) : $get;
        }

        $server['REQUEST_URI']  = $info['path'] . ('' !== $queryString ? '?' . $queryString : '');
        $server['QUERY_STRING'] = $queryString;
        $options['cookie']      = $cookie;
        $options['param']       = $params;
        $options['file']        = $files;
        $options['server']      = $server;
        $options['url']         = $server['REQUEST_URI'];
        $options['baseUrl']     = $info['path'];
        $options['pathinfo']    = '/' == $info['path'] ? '/' : ltrim($info['path'], '/');
        $options['method']      = $server['REQUEST_METHOD'];
        $options['domain']      = isset($info['scheme']) ? $info['scheme'] . '://' . $server['HTTP_HOST'] : '';
        $options['content']     = $content;
        foreach ($options as $name => $item) {
            if (property_exists($this, $name)) {
                $this->$name = $item;
            }
        }
        return $this;
    }
1081219
public static function factory($config = array()) {
        $default = array(
            'serverUrls' => null,
            'user' => null,
            'publicKey' => null,
            'privateKey' => null,
        );

        // Backwards-compatibility with old client where user === publicKey
        if (!isset($config['user']) && isset($config['publicKey'])) {
            $config['user'] = $config['publicKey'];
        }

        $required = array('serverUrls', 'publicKey', 'privateKey', 'user');
        $config = Collection::fromConfig($config, $default, $required);

        if (!is_array($serverUrls = $config->get('serverUrls')) || empty($serverUrls)) {
            throw new InvalidArgumentException('serverUrls must be an array');
        }

        // Create the client and attach the service description
        return new self($serverUrls[0], $config);
    }
1217634
public static function createUri(array $server = [])
    {
        $server += $_SERVER;
        $server = static::normalizeServer($server);
        $headers = static::marshalHeaders($server);

        return static::marshalUriFromServer($server, $headers);
    }
858828
private function determinePath(array $server): string
    {
        $path = '';
        if (strpos($server['SCRIPT_NAME'], 'index.php') !== false) {
            $path = str_replace('index.php', '', $server['SCRIPT_NAME']);
        }

        $parts = explode('?', $server['REQUEST_URI']);

        $length = 0;
        if ($path !== '' && strpos($parts[0], $path) === 0) {
            $length = strlen($path);
        }

        return '/' . ltrim(substr($parts[0], $length), '/');
    }
862748
private function withQueryString(UriInterface $uri, array $server) : UriInterface {
		if (isset($server['QUERY_STRING'])) {
			return $uri->withQuery($server['QUERY_STRING']);
		} else {
			if (isset($server['REQUEST_URI'])) {
				$requestUri = \explode('?', $server['REQUEST_URI'], 2);
				if (\count($requestUri) > 1) {
					return $uri->withQuery($requestUri[1]);
				}
			}
		}

		return $uri;
	}
1251234
public static function createServerRequestFromGlobals()
    {
        $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
        $headers = function_exists('getallheaders') ? getallheaders() : [];

        return new static($method, static::createUriFromGlobal($_SERVER), $headers, new PhpInputStream(), $_SERVER);
    }
418275
protected function prepareUri($server)
    {
        $uri = new Uri('');

        if ((isset($server['HTTPS']) && $server['HTTPS'] != 'off') ||
            (isset($server['HTTP_X_FORWARDED_PROTO']) && $server['HTTP_X_FORWARDED_PROTO'] == 'https')
        ) {
            $schema = 'https';
        } else {
            $schema = 'http';
        }

        $parsedUrl = parse_url($server['REQUEST_URI']);
        $username = isset($server['PHP_AUTH_USER']) ? $server['PHP_AUTH_USER'] : null;
        $password = isset($server['PHP_AUTH_PW']) ? $server['PHP_AUTH_PW'] : null;

        return $uri->withScheme($schema)
            ->withHost($server['HTTP_HOST'])
            ->withPort($server['SERVER_PORT'])
            ->withPath(isset($parsedUrl['path']) ? $parsedUrl['path'] : '/')
            ->withUserInfo($username, $password)
            ->withQuery(isset($parsedUrl['query']) ? $parsedUrl['query'] : '');
    }