Return HTTP protocol version (X.Y)

@param   array $server The $_SERVER supperglobal.

@return  string  Protocol version.
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];
    }
1047406
public function version()
    {
        $json = (string) $this->client->request('GET', '/')->getBody();
        $value = JSONEncoder::decode($json);

        return $value['version'];
    }
481161
public function getServerVersion()
	{
		try
		{
			$version = $this->pdo->getAttribute(\PDO::ATTR_SERVER_VERSION);
		}
		catch(\PDOException $e)
		{
			return NULL;
		}
		
		return $version;
	}
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'] : '');
    }
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);
        }
    }
1175438
private static function aggregateHeaderFromServer($server = [])
    {
        $header = [];

        if (isset($server['HTTP_HOST'])) {
            $header['Host'] = $server['HTTP_HOST'];
        }

        if (isset($server['HTTP_USER_AGENT'])) {
            $header['User-Agent'] = $server['HTTP_USER_AGENT'];
        }

        if (isset($server['HTTP_CONNECTION'])) {
            $header['Connection'] = $server['HTTP_CONNECTION'];
        }

        if (isset($server['HTTP_ACCEPT_ENCODING'])) {
            $header['Accept-Encoding'] = $server['HTTP_ACCEPT_ENCODING'];
        }

        if (isset($server['HTTP_ACCEPT_LANGUAGE'])) {
            $header['Accept-Language'] = $server['HTTP_ACCEPT_LANGUAGE'];
        }

        if (isset($server['HTTP_CACHE_CONTROL'])) {
            $header['Cache-Control'] = $server['HTTP_CACHE_CONTROL'];
        }

        if (isset($server['HTTP_ACCEPT'])) {
            $header['Accept'] = $server['HTTP_ACCEPT'];
        }

        return $header;
    }
141411
private static function fetchHostname(array $server): array
    {
        $server += ['SERVER_PORT' => null];
        if (null !== $server['SERVER_PORT']) {
            $server['SERVER_PORT'] = (int) $server['SERVER_PORT'];
        }

        if (isset($server['HTTP_HOST'])) {
            preg_match(',^(?<host>(\[.*\]|[^:])*)(\:(?<port>[^/?\#]*))?$,x', $server['HTTP_HOST'], $matches);

            return [
                $matches['host'],
                isset($matches['port']) ? (int) $matches['port'] : $server['SERVER_PORT'],
            ];
        }

        if (!isset($server['SERVER_ADDR'])) {
            throw new SyntaxError('The host could not be detected');
        }

        if (false === filter_var($server['SERVER_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
            $server['SERVER_ADDR'] = '['.$server['SERVER_ADDR'].']';
        }

        return [$server['SERVER_ADDR'], $server['SERVER_PORT']];
    }
1054520
private static function fetchRequestUri(array $server): array
    {
        $server += ['IIS_WasUrlRewritten' => null, 'UNENCODED_URL' => '', 'PHP_SELF' => '', 'QUERY_STRING' => null];
        if ('1' === $server['IIS_WasUrlRewritten'] && '' !== $server['UNENCODED_URL']) {
            return explode('?', $server['UNENCODED_URL'], 2) + [1 => null];
        }

        if (isset($server['REQUEST_URI'])) {
            [$path, ] = explode('?', $server['REQUEST_URI'], 2);
            $query = ('' !== $server['QUERY_STRING']) ? $server['QUERY_STRING'] : null;

            return [$path, $query];
        }

        return [$server['PHP_SELF'], $server['QUERY_STRING']];
    }
577893
protected static function resolveHostPort($server)
    {
        if (isset($server['HTTP_HOST'])) {
            $host = $server['HTTP_HOST'];
        } elseif (isset($server['SERVER_NAME'])) {
            $host = $server['SERVER_NAME'];
        } else {
            throw new InvalidArgumentException(
                'Undefined HTTP host in server params'
            );
        }

        $port = null;

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

        if (preg_match('/:(\d+)$/', $host, $matches)) {
            $host = rtrim($host, ":{$matches[1]}");
            $port = (int)$matches[1];
        }

        return $host . ($port !== null ? ":$port" : '');
    }
722564
public static function getVersion(array $server = null)
    {
        $protocol = static::make($server);

        if (! preg_match('#\A(?:HTTP/)?(?P<version>\d{1}\.\d+)\Z#', $protocol, $matches)) {
            throw new UnexpectedValueException(sprintf(
                'Unrecognized protocol version "%s".',
                $server['SERVER_PROTOCOL']
            ));
        }

        return $matches['version'];
    }
121442
public static function capture(array $server = null)
    {
        if (!$server) {
            $server = $_SERVER;
        }

        $source = 'http:';
        if (isset($server['HTTPS']) && $server['HTTPS'] && $server['HTTPS'] != 'off') {
            $source = 'https:';
        }
        if (isset($server['HTTP_HOST'])) {
            $source .= '//' . $server['HTTP_HOST'];
        }
        if (isset($server['REQUEST_URI'])) {
            $source .= $server['REQUEST_URI'];
        }

        $url = new static($source);
        $url->username = $server['PHP_AUTH_USER'] ?? null;
        $url->password = $server['PHP_AUTH_PW'] ?? null;

        return $url;
    }
385120
public function getServerVersion()
    {
        if ($this->client) {
            return $this->client->getServerVersion();
        }

        $connection = new Connection($this->config);
        
        return $connection->getAttribute(\PDO::ATTR_SERVER_VERSION);
    }
637701
public static function getHostAndPortFromArray(array $server): array
    {
        if (isset($server['HTTP_HOST'])) {
            return self::getHostAndPortFromHost($server['HTTP_HOST']);
        }

        if (!isset($server['SERVER_NAME'])) {
            return ['', null];
        }

        $host = $server['SERVER_NAME'];
        $port = null;
        if (isset($server['SERVER_PORT'])) {
            $port = (int) $server['SERVER_PORT'];
        }

        // Misinterpreted IPv6-Address
        // Reported for Safari on Windows
        if (isset($server['SERVER_ADDR']) && \preg_match('/^\[[0-9a-fA-F\:]+\]$/', $host)) {
            $host = '[' . $server['SERVER_ADDR'] . ']';
            $port = $port ?: 80;
            if ($port . ']' === \substr($host, \strrpos($host, ':') + 1)) {
                // The last digit of the IPv6-Address has been taken as port
                // Unset the port so the default port can be used
                $port = null;
            }
        }

        return [$host, $port];
    }
1211450
public function withProtocolVersion($version)
    {
        $request = clone $this;
        if (method_exists($request, 'setProtocolVersion')) {
            $request->setProtocolVersion($version);
        } else {
            $request->server->set('SERVER_PROTOCOL', $version);
        }

        return $request;
    }
76194
public function httpVersion($version) {

		if(false === defined($version)) {
			return trigger_error(sprintf('Argument 1 passed to %s() is not a valid HTTP protocol version', __METHOD__), E_USER_ERROR);
		}

		$this -> options[CURLOPT_HTTP_VERSION] = constant($version);

		return $this;
	}
404264
public function getServerVersion($details = false)
    {
        $url = Urls::URL_ADMIN_VERSION;

        if ($details) {
            $url = UrlHelper::appendParamsUrl($url, ['details' => true]);
        }

        $response = $this->getConnection()->get($url);
        $data     = $response->getJson();

        if ($details) {
            return $data;
        }

        return $data['version'];
    }
1319287
public function getProtocolVersion()
    {
        if ($this->protocol) {
            return $this->protocol;
        }

        // Lazily populate this data as it is generally not used.
        preg_match('/^HTTP\/([\d.]+)$/', $this->getEnv('SERVER_PROTOCOL'), $match);
        $protocol = '1.1';
        if (isset($match[1])) {
            $protocol = $match[1];
        }
        $this->protocol = $protocol;

        return $this->protocol;
    }