Find cookies matching the scheme, host, and path

@param string $scheme The http scheme to match
@param string $host The host to match.
@param string $path The path to match
@return array An array of cookie name/value pairs
180790
protected function findMatchingCookies($scheme, $host, $path)
    {
        $out = [];
        $now = new DateTimeImmutable('now', new DateTimeZone('UTC'));
        foreach ($this->cookies as $cookie) {
            if ($scheme === 'http' && $cookie->isSecure()) {
                continue;
            }
            if (strpos($path, $cookie->getPath()) !== 0) {
                continue;
            }
            $domain = $cookie->getDomain();
            $leadingDot = substr($domain, 0, 1) === '.';
            if ($leadingDot) {
                $domain = ltrim($domain, '.');
            }

            if ($cookie->isExpired($now)) {
                continue;
            }

            $pattern = '/' . preg_quote($domain, '/') . '$/';
            if (!preg_match($pattern, $host)) {
                continue;
            }

            $out[$cookie->getName()] = $cookie->getValue();
        }

        return $out;
    }
196495
public function EntityContexts( $entity, $scheme = null )
	{
		$filtered = array_filter( $this->contexts, function ( $context ) use( $entity, $scheme ) {

			// The context may be invalid in which case exclude
			if ( ! isset( $context['entity']['identifier']['value'] ) ) return false;

			if ( $context['entity']['identifier']['value'] == $entity )
			{
				// If supplied also check the scheme
				return $scheme != null && isset( $context['entity']['identifier']['scheme'] )
				? ( strtolower( $scheme ) == strtolower( $context['entity']['identifier']['scheme'] ) )
				: true;
			}

			return false;
		} );

		return new ContextsFilter( $this->instance, $filtered );
	}
945585
protected function setScheme($scheme)
    {
        $this->uriString = null;

        $this->scheme = strtolower(rtrim($scheme, ':/'));

        return $this;
    }
720049
public function validateScheme($scheme = null)
    {
        if ($scheme === null) {
            $parsed = parse_url($this->uri);
            $scheme = isset($parsed['host']) ? $parsed['host'] : $parsed['path'];
        }
        return in_array($scheme, $this->schemes);
    }
75051
public function getRedeemScriptByPath($path) {
        $walletScript = $this->getWalletScriptByPath($path);

        $redeemScript = $walletScript->isP2SH() ? $walletScript->getRedeemScript() : null;
        $witnessScript = $walletScript->isP2WSH() ? $walletScript->getWitnessScript() : null;
        return [$walletScript->getAddress()->getAddress(), $redeemScript, $witnessScript];
    }
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;
    }
234456
protected function getRootUrl($scheme, $root = null)
	{
		if (is_null($root))
		{
			if (is_null($this->cachedRoot))
			{
				$this->cachedRoot = $this->forcedRoot ?: $this->request->root();
			}

			$root = $this->cachedRoot;
		}

		$start = starts_with($root, 'http://') ? 'http://' : 'https://';

		return preg_replace('~'.$start.'~', $scheme, $root, 1);
	}
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;
        }
    }
31355
public function setScheme($scheme)
    {
        $this->scheme = strtolower((string) $scheme);

        $this->ssl = ($this->scheme === 'https');

        return $this;
    }
402766
public static function matchCookieDomain($cookieDomain, $host)
    {
        if (! $cookieDomain) {

            throw new Zend_Http_Exception("\$cookieDomain is expected to be a cookie domain");
        }

        if (! $host) {

            throw new Zend_Http_Exception("\$host is expected to be a host name");
        }

        $cookieDomain = strtolower($cookieDomain);
        $host = strtolower($host);

        if ($cookieDomain[0] == '.') {
            $cookieDomain = substr($cookieDomain, 1);
        }

        // Check for either exact match or suffix match
        return ($cookieDomain == $host ||
                preg_match('/\.' . preg_quote($cookieDomain) . '$/', $host));
    }
38299
public function setCookie($key, $value)
    {
        $name_chars = array();
        foreach (str_split($key) as $name_char) {
            if (!isset($this->rfc2616[$name_char])) {
                $name_chars[] = rawurlencode($name_char);
            } else {
                $name_chars[] = $name_char;
            }
        }

        $value_chars = array();
        foreach (str_split($value) as $value_char) {
            if (!isset($this->rfc6265[$value_char])) {
                $value_chars[] = rawurlencode($value_char);
            } else {
                $value_chars[] = $value_char;
            }
        }

        $this->cookies[implode('', $name_chars)] = implode('', $value_chars);
        $this->setOpt(CURLOPT_COOKIE, implode('; ', array_map(function ($k, $v) {
            return $k . '=' . $v;
        }, array_keys($this->cookies), array_values($this->cookies))));
    }
507285
protected function _matchPath($domains, $path)
    {
        $ret = array();

        foreach ($domains as $dom => $paths_array) {
            foreach (array_keys($paths_array) as $cpath) {
                if (Zend_Http_Cookie::matchCookiePath($cpath, $path)) {
                    if (! isset($ret[$dom])) {
                        $ret[$dom] = array();
                    }

                    $ret[$dom][$cpath] = $paths_array[$cpath];
                }
            }
        }

        return $ret;
    }
1283160
protected function getRootUrl($scheme, $root = null)
	{
		$root = $root ?: $this->request->root();

		$start = starts_with($root, 'http://') ? 'http://' : 'https://';

		return preg_replace('~'.$start.'~', $scheme, $root, 1);
	}
168889
public static function matchCookiePath($cookiePath, $path)
    {
        if (! $cookiePath) {

            throw new Zend_Http_Exception("\$cookiePath is expected to be a cookie path");
        }

        if (! $path) {

            throw new Zend_Http_Exception("\$path is expected to be a host name");
        }

        return (strpos($path, $cookiePath) === 0);
    }
299066
public static function getHome($path = '',$scheme = '')
	{
		$domain = Config::get('@.DOMAIN');
		if(empty($domain))
		{
			$domain = $_SERVER['HTTP_HOST'] . strtr(dirname($_SERVER['SCRIPT_NAME']), '\\','/');
		}
		if('' === $scheme)
		{
			$scheme = Config::get('@.URL_PROTOCOL');
			if(empty($scheme))
			{
				$scheme=Request::getProtocol();
			}
		}
		if((!isset($path[0]) || '/' !== $path[0]) && '/' !== substr($domain,-1,1))
		{
			$path = '/' . $path;
		}
		return $scheme . $domain . $path;
	}
1100105
public function withCookie($key, $value, $expire = 0, $path = '/', $domain = '', $secure = false, $httponly = false)
    {
        $self = clone $this;
        $self->cookies[] = [
            'key'       => $key,
            'value'     => $value,
            'expire'    => $expire,
            'path'      => $path,
            'domain'    => $domain,
            'secure'    => $secure,
            'httponly'  => $httponly,
        ];
        return $self;
    }
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);
    }