Filters the scheme to ensure it is a valid scheme.

@param string $scheme Scheme name.
@return string Filtered scheme.
@throws \InvalidArgumentException If the scheme is invalid.
342230
private function _filterScheme($scheme)
    {
        $scheme = strtolower($scheme);
        $scheme = preg_replace('#:(//)?$#', '', $scheme);

        if (!preg_match('/\A[a-z][a-z0-9\+\-\.]+\z/', $scheme)) {
            throw new InvalidArgumentException(sprintf(
                'Invalid scheme "%s" specified; must be a valid RFC 3986 scheme',
                $scheme
            ));
        }

        if ($scheme && !in_array($scheme, $this->allowedSchemes)) {
            throw new InvalidArgumentException(sprintf(
                'Unsupported scheme "%s"; must be any empty string or in the set (%s)',
                $scheme,
                implode(', ', array_keys($this->allowedSchemes))
            ));
        }

        return $scheme;
    }
747767
protected function createFilter($filter)
    {
        if (is_callable($filter)) {
            return call_user_func($filter);
        } elseif (is_string($filter)) {
            return new $filter();
        } elseif (is_object($filter)) {
            return $filter;
        } else {
            throw new \InvalidArgumentException("Cannot convert $filter to filter");
        }
    }
902407
public function authorization(string $scheme, string $value): HttpRequest
    {
        if (empty($scheme)) {
            throw new \InvalidArgumentException("Scheme was null or empty");
        }
        if (empty($value)) {
            throw new \InvalidArgumentException("Value was null or empty");
        }
        return $this->header("Authorization", $scheme . " " . $value);
    }
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;
        }
    }
1162996
protected function filtreCode($code)
    {
        if (is_numeric($code)) {
            $code = (int) $code;
        }
        if (!isset($this->reasonPhraseDefault[ $code ])) {
            throw new \InvalidArgumentException('Status code is invalid.');
        }

        return $code;
    }
1148618
public function setScheme($scheme)
    {
        // validate scheme
        try {
            $scheme = new StringObject($scheme);
        } catch (\Exception $e) {
            throw new UrlObjectException($e->getMessage());
        }

        if (!$scheme->endsWith('://')) {
            $scheme->val($scheme->val() . '://');
        }

        // set the scheme
        $this->scheme = $scheme->trimRight('://')->val();
        $this->rebuildUrl();

        return $this;
    }
724152
private static function isSupportedUrlScheme($url, &$scheme) {
    $scheme = parse_url($url, PHP_URL_SCHEME);

    return (is_null($scheme) ||
            in_array($scheme, static::$supported_url_schemes));
  }
255194
public function setFilter($name, $filter)
    {
        if (!(
            is_callable($filter) ||
            class_exists($filter) ||
            method_exists($filter, 'parse')
        )) {
            throw new InvalidArgumentException(
                'Invalid ' . $name . ' filter given: ' .
                'it must be a callable or a class name.'
            );
        }

        return $this->getCompiler()->setFilter($name, $filter);
    }
896110
public static function tryAddUrlScheme($url, $scheme = 'http')
    {
        $urlScheme = parse_url($url, PHP_URL_SCHEME);

        if (empty($urlScheme)) {
            $url = "$scheme://".$url;
        }

        return $url;
    }
452506
private function isValidScheme(string $scheme): bool
    {
        $validSchemes = ['file', 'git+http', 'git+https'];
        return \in_array(\strtolower($scheme), $validSchemes, true);
    }
1032158
public function setSchemeName($schemeName)
    {
        if (
                !is_string($schemeName)
             && !is_null($schemeName)
        ) {
            throw new \InvalidArgumentException(
                __CLASS__ . ' ' . __METHOD__ . ': Not a string'
            );
        }

        $this->schemeName = $schemeName;

        return $this;
    }
1205376
public static function setForcedScheme($scheme = null)
    {
        if (! is_string($scheme) && ! is_null($scheme)) {
            throw new InvalidArgumentException(sprintf(
                'Invalid scheme provided; must be an string or a null, "%s" received.',
                is_object($scheme) ? get_class($scheme) : gettype($scheme)
            ));
        }
        static::$forcedScheme = $scheme;
    }
675593
public function assertSchemeIsNot($scheme)
    {
        $actual = parse_url($this->driver->getCurrentURL(), PHP_URL_SCHEME) ?? '';

        PHPUnit::assertNotEquals(
            $scheme, $actual,
            "Scheme [{$scheme}] should not equal the actual value."
        );

        return $this;
    }
804543
protected static function filterScheme($scheme)
    {
        if (! is_string($scheme)) {
            throw new InvalidArgumentException(sprintf(
                'Invalid scheme provided; must be a string argument; ; received %s',
                (is_object($scheme) ? get_class($scheme) : gettype($scheme))
            ));
        }

        $scheme = str_replace('://', '', strtolower($scheme));

        if (! isset(static::$standardSchemes[$scheme])) {
            throw new InvalidArgumentException(sprintf(
                'Unsupported scheme "%s"; must be any empty string or in the set (%s)',
                $scheme,
                implode(', ', array_keys(static::$standardSchemes))
            ));
        }

        return $scheme;
    }
424334
public function withScheme(string $scheme): self
    {
        $newConstraints = $this->constraints;
        $newConstraints[self::CONSTRAINT_SCHEME] = $scheme;
        return new static($newConstraints);
    }
394037
private function parseScheme(array $locationParts): void
    {
        if (! $this->isValidScheme($locationParts['scheme'])) {
            throw new InvalidArgumentException(
                sprintf('"%s" is not a valid scheme.', $locationParts['scheme'])
            );
        }

        $this->scheme = strtolower($locationParts['scheme']);
    }
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];
    }