Create a new instance with the scheme constraint added

@param string $scheme The URI scheme to force, usually "http" or "https"
@return UriConstraints
424334
public function withScheme(string $scheme): self
    {
        $newConstraints = $this->constraints;
        $newConstraints[self::CONSTRAINT_SCHEME] = $scheme;
        return new static($newConstraints);
    }
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");
    }
70065
public function setScheme($scheme)
    {
        if (! is_string($scheme)) {

            throw new InvalidArgumentException("Scheme must be a string ($scheme)");
        }

        $scheme = strtolower($scheme);

        if (preg_match_all('`^' . self::$_regexScheme . '$`', $scheme, $matches) !== 1) {

            throw new InvalidArgumentException('Scheme names consist of a sequence of characters beginning with a'
               . ' letter and followed by any combination of letters, digits, plus ("+"), period (".")'
               . ', or hyphen ("-")');
        }

        $this->_scheme = $scheme;
    }
717456
public function assertSchemeIs($scheme)
    {
        $pattern = str_replace('\*', '.*', preg_quote($scheme, '/'));

        $actual = parse_url($this->driver->getCurrentURL(), PHP_URL_SCHEME) ?? '';

        PHPUnit::assertRegExp(
            '/^'.$pattern.'$/u', $actual,
            "Actual scheme [{$actual}] does not equal expected scheme [{$pattern}]."
        );

        return $this;
    }
1120637
public function setScheme(array $scheme)
    {
        $scheme_handler = new SchemeHandler();
        $scheme_handler->setScheme($scheme);
        
        $this->injectSchemeHandler($scheme_handler);
    }
1168070
public function createSchemeHeader($scheme)
    {
        $schemeObj = $this->getScheme($scheme);
        $value = $schemeObj->createResponseHeaderValue();

        return new HttpHeader($this->schemeHeader, trim($scheme . ' ' . $value));
    }
698466
static protected function buildPatternFromScheme(URLScheme $scheme)
    {
		// generate a unique random string
		$uniq = md5(mt_rand());

		// replace the wildcard sub-domain if exists
		$scheme = str_replace(
			'://'.self::WILDCARD_CHARACTER.'.',
			'://'.$uniq,
			$scheme->__tostring()
		);

		// replace the wildcards
		$scheme = str_replace(
			self::WILDCARD_CHARACTER,
			$uniq,
			$scheme
		);

		// set the pattern wrap
		$wrap = '|';

		// quote the pattern
		$pattern = preg_quote($scheme, $wrap);

		// replace the unique string by the character class
		$pattern = str_replace($uniq, '.*', $pattern);

		return $wrap.$pattern.$wrap.'iu';
    }
292049
public function getScheme($scheme, $config, $context)
    {
        if (!$config) {
            $config = HTMLPurifier_Config::createDefault();
        }

        // important, otherwise attacker could include arbitrary file
        $allowed_schemes = $config->get('URI.AllowedSchemes');
        if (!$config->get('URI.OverrideAllowedSchemes') &&
            !isset($allowed_schemes[$scheme])
        ) {
            return;
        }

        if (isset($this->schemes[$scheme])) {
            return $this->schemes[$scheme];
        }
        if (!isset($allowed_schemes[$scheme])) {
            return;
        }

        $class = 'HTMLPurifier_URIScheme_' . $scheme;
        if (!class_exists($class)) {
            return;
        }
        $this->schemes[$scheme] = new $class();
        return $this->schemes[$scheme];
    }
87272
protected function setScheme($scheme)
    {
        $scheme = strtolower($scheme);
        
        if ($scheme !== '' && !$this->isSupportedScheme($scheme)) {
            throw new \InvalidArgumentException("Invalid or unsupported scheme '$scheme'");
        }
        
        $this->scheme = $scheme;
    }
410248
public function internalCreateAbsoluteUrl($params, $scheme = null)
    {
        $params = (array) $params;
        $url = $this->internalCreateUrl($params);
        if (strpos($url, '://') === false) {
            $url = $this->getHostInfo() . $url;
        }
        if (is_string($scheme) && ($pos = strpos($url, '://')) !== false) {
            $url = $scheme . substr($url, $pos);
        }
        return $url;
    }
1020137
public function schemeClass($scheme)
    {
        if (null === $scheme) {
            return $this->defaultClass();
        }

        $scheme = strtolower($scheme);
        $schemeClasses = $this->schemeClasses();
        if (!array_key_exists($scheme, $schemeClasses)) {
            return $this->defaultClass();
        }

        return $schemeClasses[$scheme];
    }
33136
public function createUrl($args, $scheme = false)
    {
        $context = $this->_context;

        if (is_string($args)) {
            if (($pos = strpos($args, '?')) !== false) {
                $path = substr($args, 0, $pos);
                parse_str(substr($args, $pos + 1), $params);
            } else {
                $path = $args;
                $params = [];
            }
        } else {
            $path = $args[0];
            unset($args[0]);
            $params = $args;
        }

        $area = $context->area;
        $controller = $context->controller;
        if ($path === '') {
            $action = $context->action;
            $ca = $area ? "{$area}/{$controller}/$action" : "{$controller}/$action";
        } elseif (strpos($path, '/') === false) {
            $ca = $area ? "{$area}/{$controller}/$path" : "{$controller}/$path";
        } elseif ($path === '/') {
            $ca = '';
        } elseif ($path[0] === '/') {
            $ca = substr($path, 1);
        } elseif ($area) {
            $ca = $area . '/' . $path;
        } else {
            $ca = rtrim($path, '/');
        }

        while (($pos = strrpos($ca, '/index')) !== false && $pos + 6 === strlen($ca)) {
            $ca = substr($ca, 0, $pos);
        }

        $url = $this->alias->get('@web') . $this->_prefix . '/' . lcfirst($ca);
        if ($url !== '/') {
            $url = rtrim($url, '/');
        }

        if ($params !== []) {
            $fragment = null;
            if (isset($params['#'])) {
                $fragment = $params['#'];
                unset($params['#']);
            }

            /** @noinspection NotOptimalIfConditionsInspection */
            if ($params !== []) {
                $url .= '?' . http_build_query($params);
            }
            if ($fragment !== null) {
                $url .= '#' . $fragment;
            }
        }

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

        $clone = clone $this;
        $clone->scheme = $scheme;

        return $clone;
    }
743124
private static function isAllowedScheme($scheme)
    {
        if (preg_match(AbstractRequest::HTTP, $scheme) === 1) {
            return 'http';
        } elseif (preg_match(AbstractRequest::FTP, $scheme) === 1) {
            return 'ftp';
        } elseif (preg_match(AbstractRequest::SSH, $scheme) === 1) {
            return 'ssh';
        } else {
            return false;
        }
    }
523099
public function matchesScheme($scheme)
    {
        $scheme = strtolower($scheme);
        $secure = $this->_data['secure'];
        return ($secure && $scheme === 'https') || (!$secure && $scheme === 'http');
    }
202643
public function get($scheme = self::REL)
    {
        $data = $this->data;
        if ($scheme == self::REL) {
            unset($data['scheme'], $data['host'], $data['user'], $data['pass'], $data['port']);
            return $this->build($data);
        }
        if (!isset($data['host'])) {
            $data['host'] = $this->request->getHost();
        }
        if (!isset($data['scheme'])) {
            $scheme = self::SHORT_ABS;
        }

        if ($scheme == self::SHORT_ABS) {
            unset($data['scheme']);
            $url = $this->build($data, '//');
        } else {
            $url = $this->build($data);
        }

        return $this->asProtect($url, $data['host']);
    }
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));
    }