@param string $scheme
@param string $authority
@param string $path
@param string $query
@param string $fragment

@return string
979300
public static function composeComponents($scheme, $authority, $path, $query, $fragment = '')
    {
        $uri = '';

        if ($scheme !== '') {
            $uri .= $scheme . ':';
        }

        if ($authority !== '') {
            $uri .= '//' . $authority;
        }

        $uri .= $path;

        if ($query !== '') {
            $uri .= '?' . $query;
        }

        if ($fragment !== '') {
            $uri .= '#' . $fragment;
        }

        return $uri;
    }
1285979
public static String buildURIAsString(String scheme, String authority, String path,
            String query, String fragment) throws URISyntaxException {
        URI helperURI;
        try {
            helperURI = new URI(scheme, authority, path, query, fragment);
        } catch (URISyntaxException e) {
            return NetworkInterfaceURI.buildURIToString(scheme, authority, path, query, fragment);
        }
        return helperURI.toString();
    }
753521
protected function marshalScheme($scheme): ? string
    {
        if ( null === $scheme ) {
            return null;
        }

        if ( ! is_string($scheme) ) {
            throw new UriException(
                'Scheme must be a string'
            );
        }

        return strtolower($scheme);
    }
346644
private void initialize(String scheme, String authority, String path) {
		try {
			this.uri = new URI(scheme, authority, normalizePath(path), null, null).normalize();
		} catch (URISyntaxException e) {
			throw new IllegalArgumentException(e);
		}
	}
562263
private static function isValidUriScheme(?string $scheme): bool
    {
        // http://tools.ietf.org/html/rfc3986#section-3
        // The scheme and path components are required, though the path may be
        // empty (no characters)
        if ($scheme === null || $scheme === '') {
            return false;
        }

        // http://tools.ietf.org/html/rfc3986#section-3.1
        // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
        $pattern = '/\A[a-z][a-z0-9+.\-]*\z/i';

        return !!preg_match($pattern, $scheme);
    }
858819
public function get($args = [], $scheme = false)
    {
        if (is_string($args)) {
            $url = $args;
            if ($url === '') {
                return $this->router->createUrl($url, $scheme);
            } elseif ($url[0] === '/') {
                $url = $this->alias->get('@web') . $url;
                if (!$scheme) {
                    return $url;
                }
            } elseif (parse_url($url, PHP_URL_SCHEME)) {
                return $url;
            } else {
                return $this->router->createUrl($url, $scheme);
            }
            $anchor = null;
            $args = '';
        } else {
            $url = $args[0];
            if ($url === '') {
                return $this->router->createUrl($args, $scheme);
            } elseif ($url[0] === '/') {
                $url = $this->alias->get('@web') . $url;
            } elseif (parse_url($url, PHP_URL_SCHEME)) {
                null;
            } else {
                return $this->router->createUrl($args, $scheme);
            }

            $anchor = isset($args['#']) ? $args['#'] : null;
            unset($args[0], $args['#']);
        }

        if ($args) {
            $url .= (strpos($url, '?') !== false ? '&' : '?') . http_build_query($args);
        }

        if ($anchor !== null) {
            $url .= '#' . $anchor;
        }

        if ($scheme) {
            if ($scheme === true) {
                $scheme = $this->request->getScheme();
            }
            return ($scheme === '//' ? $scheme : "$scheme://") . $this->request->getServer('HTTP_HOST') . $url;
        } else {
            return $url;
        }
    }
617167
public function withScheme(string $scheme): URI
    {
        $result = clone $this;
        $result->scheme = $this->filterScheme($scheme);

        return $result;
    }
859056
public function toString()
    {
        // reconstruct authority
        $authority = null;
        // there is a rendering difference between a null authority
        // (http:foo-bar) and an empty string authority
        // (http:///foo-bar).
        if (!is_null($this->host)) {
            $authority = '';
            if (!is_null($this->userinfo)) {
                $authority .= $this->userinfo . '@';
            }
            $authority .= $this->host;
            if (!is_null($this->port)) {
                $authority .= ':' . $this->port;
            }
        }

        // Reconstruct the result
        // One might wonder about parsing quirks from browsers after
        // this reconstruction.  Unfortunately, parsing behavior depends
        // on what *scheme* was employed (file:///foo is handled *very*
        // differently than http:///foo), so unfortunately we have to
        // defer to the schemes to do the right thing.
        $result = '';
        if (!is_null($this->scheme)) {
            $result .= $this->scheme . ':';
        }
        if (!is_null($authority)) {
            $result .= '//' . $authority;
        }
        $result .= $this->path;
        if (!is_null($this->query)) {
            $result .= '?' . $this->query;
        }
        if (!is_null($this->fragment)) {
            $result .= '#' . $this->fragment;
        }

        return $result;
    }
1270137
private function normalizeScheme($scheme)
    {
        if (!is_string($scheme) && !method_exists($scheme, '__toString')) {
            throw new InvalidArgumentException('Uri scheme must be a string');
        }

        $scheme = str_replace('://', '', strtolower((string) $scheme));
        if (!isset($this->validSchema[$scheme])) {
            throw new InvalidArgumentException('Uri scheme must be one of: "", "https", "http"');
        }

        return $scheme;
    }
1363282
public function request(string $verb, string $path, array $query = [], array $options = [])
    {
        $options['query'] = $query;

        if (!empty($options['query']['filter']) && is_array($options['query']['filter'])) {
            // Default to an AND filter.
            $options['query']['filter'] = implode(',', $options['query']['filter']);
        }
        $response = $this->makeRequest($verb, $path, $query, $options);

        return $this->processResponse($response);
    }
319299
public final function withScheme($scheme): UriInterface
   {
       if (!is_string($scheme)
        || !($parsedScheme = $this->parseScheme($scheme))
        || $parsedScheme !== strtolower($scheme)) {
           throw new InvalidArgumentException(
               "Can't get with scheme: not supported");
       }
       return $this->with("scheme", $parsedScheme);
   }
1367025
static function createUriString($scheme, $authority, $path, $query, $fragment) {
        $uri = '';
        if (!empty($scheme)) {
            $uri .= $scheme . ':';
        }
        $hierPart = '';
        if (!empty($authority)) {
            if (!empty($scheme)) {
                $hierPart .= '//';
            }
            $hierPart .= $authority;
        }
        if ($path != null) {
            // Add a leading slash if necessary.
            if ($hierPart && substr($path, 0, 1) !== '/') {
                $hierPart .= '/';
            }
            $hierPart .= $path;
        }
        $uri .= $hierPart;
        if ($query != null) {
            $uri .= '?' . $query;
        }
        if ($fragment != null) {
            $uri .= '#' . $fragment;
        }
        return $uri;
    }
855660
public function getUri(): string
    {
        $uri = '';

        if ( null !== $this->scheme ) {
            $uri .= $this->scheme.':';
        }

        $authority = $this->getAuthority();

        if ( null !== $authority || $this->scheme === 'file' ) {
            $uri .= '//'.$authority;
        }

        $uri .= $this->path;

        if ( null !== $this->query ) {
            $uri .= '?'.$this->query;
        }

        if ( null !== $this->fragment ) {
            $uri .= '#'.$this->fragment;
        }

        return $uri;
    }
731132
public function serializeURL($excludeFragmentFlag = false)
    {
        $output = $this->scheme . ':';
        if (!is_null($this->host)) {
            $output .= '//';
            if ($this->isIncludingCredentials()) {
                $output .= $this->username;
                if ($this->password !== '') {
                    $output .= ':' . $this->password;
                }
                $output .= '@';
            }
            $output .= HostProcessing::serializeHost($this->host);
            if (!is_null($this->port)) {
                $output .= ':' . $this->port;
            }
        } elseif (is_null($this->host) && $this->scheme === 'file') {
            $output .= '//';
        }
        $output .= $this->cannotBeABaseURLFlag ? $this->path[0] :  '/' . implode('/', $this->path);
        if (!is_null($this->query)) {
            $output .= '?' . $this->query;
        }
        if (!$excludeFragmentFlag && !is_null($this->fragment)) {
            $output .= '#' . $this->fragment;
        }
        return $output;
    }
271929
public function create(
        ?string $scheme = null,
        ?string $domain = null,
        $path = null,
        ?array $query = [],
        ?string $fragment = null,
        bool $trailingSlash = false
    ): string {
        return $this->make(new UrlSettings([
            'scheme'        => $scheme,
            'domain'        => $domain,
            'path'          => $path,
            'query'         => $query,
            'fragment'      => $fragment,
            'trailingSlash' => $trailingSlash,
        ]));
    }
981029
private function formatScheme(?string $scheme): ?string
    {
        if ('' === $scheme || null === $scheme) {
            return $scheme;
        }

        $formatted_scheme = strtolower($scheme);
        if (1 === preg_match(self::REGEXP_SCHEME, $formatted_scheme)) {
            return $formatted_scheme;
        }

        throw new SyntaxError(sprintf('The scheme `%s` is invalid', $scheme));
    }
1104797
private function createResource($scheme, $url)
    {
        switch ($scheme) {
            case 'http':
            case 'http*':
            case 'https':
                return $url;
            case 'rtmp':
                $parts = parse_url($url);
                $pathParts = pathinfo($parts['path']);
                $resource = ltrim(
                    $pathParts['dirname'] . '/' . $pathParts['basename'],
                    '/'
                );

                // Add a query string if present.
                if (isset($parts['query'])) {
                    $resource .= "?{$parts['query']}";
                }

                return $resource;
        }

        throw new \InvalidArgumentException("Invalid URI scheme: {$scheme}. "
            . "Scheme must be one of: http, https, or rtmp");
    }