Check that a URL can belong to a list of available domains

@param $url
@param $domains
@return bool
359799
public static function validDomains($url, $domains)
    {
        $theDomain = parse_url($url);
        foreach ($domains as $domain) {
            $check = strpos($theDomain['host'], $domain->client_domain);
            if ($check || $check === 0) {
                return true;
            }
        }
        return false;
    }
805572
public static function domainSupportsHttps($domain)
    {
        if (Kwf_Config::getValue('server.https') === true) {
            if ($domains = Kwf_Config::getValueArray('server.httpsDomains')) {
                if ($domains && !in_array($domain, $domains)) {
                    foreach ($domains as $d) {
                        if (substr($d, 0, 2) == '*.') {
                            if (substr($d, 1) == substr($domain, strpos($domain, '.'))) {
                                return true;
                            }
                        }
                    }
                    return false; //current host is not in server.httpsDomains, don't use https
                }
            }
            return true;
        }
        return false;
    }
31886
public static function isInternal($url)
	{
		$current = self::getInstance()->toString(['scheme', 'host']);
		$given   = self::getInstance($url);
		$base    = $given->toString(['scheme', 'host', 'path']);
		$host    = $given->toString(['scheme', 'host']);

		if (stripos($base, $current) !== 0 && !empty($host))
		{
			return false;
		}
		return true;
	}
911020
@Override
    public boolean hasLink(String name1, String name2, String... domain) {
        if(super.hasLink(name1, name2, domain)) {
            return true;
        }
        // check name1's groups
        if (domain.length == 1) {
            try {
                List<String> groups = Optional.ofNullable(super.getRoles(name1)).orElse(new ArrayList<>());
                for(String group : groups) {
                    if(hasLink(group, name2, domain)) {
                        return true;
                    }
                }
            } catch (Error e) {
                return false;
            }
        }
        return false;
    }
534271
public function hasStaticUrlSegment(string $url) :bool {
		// if the route is dynamic (has parameters), and starts with the base segment or if it matches strictly
		return 
			($this->indexedParameters && strpos($url, $this->staticSegment) === 0) || 
			$this->url == $url;
	}
484044
public static function isURL(string $url): bool {
        return (boolean) !(filter_var($url, FILTER_SANITIZE_URL | FILTER_VALIDATE_URL) === false);
    }
796795
public function isSocialUrl($url, $socialName = false)
    {
        foreach ($this->getDefinitions() as $domain => $name) {

            if (preg_match('/(^|[\.\/])'.$domain.'([\.\/]|$)/', $url) && ($socialName === false || $name == $socialName)) {

                return true;
            }
        }

        return false;
    }
1368711
public function getRuleList($domain = null)
    {
        $list = [];

        foreach ($this->rule as $ruleDomain => $rules) {
            foreach ($rules as $rule => $items) {
                foreach ($items as $item) {
                    $val['domain'] = $ruleDomain;

                    foreach (['method', 'rule', 'name', 'route', 'pattern', 'option'] as $param) {
                        $call = 'get' . $param;
                        $val[$param] = $item->$call();
                    }

                    $list[$ruleDomain][] = $val;
                }
            }
        }

        if ($domain) {
            return isset($list[$domain]) ? $list[$domain] : [];
        }

        return $list;
    }
317666
public static function routeExists($identifier, $domain = null) {

    	if(false === is_string($identifier)) {
    		return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($identifier)), E_USER_ERROR);
    	}

    	if(null !== $domain && false === is_string($domain)) {
    		return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($domain)), E_USER_ERROR);
    	}

    	$routes = static :: getRoutes();

    	if(false === isset($routes[$identifier])) {
    		return false;
    	}

    	if(null !== $domain) {
    		return static :: domainExists($domain);
    	}

    	return true;
    }
817650
private List<String> getDomainsFromUrl(URL url) {
        String host = url.getHost();
        String[] paths = new String[] {};
        if (url.getPath() != null) {
            paths = url.getPath().split("/");
        }
        List<String> domains = new ArrayList<String>(paths.length + 1);
        StringBuilder relative = new StringBuilder().append("http://").append(host).append("/");
        domains.add(relative.toString());
        for (String path : paths) {
            if (path.length() > 0) {
                relative.append(path).append("/");
                domains.add(relative.toString());
            }
        }
        return domains;
    }
790862
public function validateLogoUrl($url)
    {
        if (empty($url)) {
            return true;
        }

        if (!is_string($url)) {
            $this->addError('url', 'Url must be a string');
            return false;
        }

        if (mb_strlen($url, 'UTF-8') > 255) {
            $this->addError('url', 'Url length has to be less or equal to 255');
            return false;
        }

        if (filter_var($url, FILTER_VALIDATE_URL) === false) {
            $this->addError('url', 'Url must contain protocol and domain name');
            return false;
        }

        return true;
    }
1143474
protected function compare($url)
    {
        $activeMenuRouteUrl = $this->getActiveMenuRoute();
        if ($this->url == $url or $url == $activeMenuRouteUrl) {
            return true;
        }
        $segments = $this->segments;
        $count    = count($segments);
        if ($count !== count(array_filter(explode('/', str_replace(url('/'), '', $url))))) {
            return false;
        }

        $segmented = url('/') . '/' . implode('/', array_slice($segments, 0, $count - 1));
        if (count($segments) > 2 && starts_with($url, $segmented)) {
            return true;
        }
        @list($domain, $area, $module, $action) = explode('/', str_replace('http://', '', $url));
        if (!isset($segments[1])) {
            return false;
        }
        return ($segments[1] == $module && isset($segments[2]) && (in_array($segments[2], ['index', 'edit']) or is_numeric($segments[2])));
    }
1276267
public function checkDomain()
    {
        // parent
        if ($this->group && ! $this->group->checkDomain())
            return false;

        if ($this->domain === null)
            return true;

        $domain = empty($_SERVER['SERVER_NAME']) ? null : $_SERVER['SERVER_NAME'];
        if ($domain === null)
            return false;

        return $domain === $this->domain;
    }
1199515
protected function isValidDomain($url)
    {
        $trusted = $this->config->trusted_sites;


        if (!empty($trusted)) {
            extract(parse_url($url));

            $host = substr($url, 0, strpos($url, $host)).$host;

            if (!$this->matchHost($host, $trusted)) {
                return false;
            }
        }
        return $url;
    }
1098652
public function purgeUrls(array $urls)
    {
        if (strpos($this->domain, 'http') === false) {
            throw new \InvalidArgumentException("'domain' is not configured for fastly driver");
        }

        if (strpos($this->domain, 'http') !== 0) {
            throw new \InvalidArgumentException("'domain' must include the protocol, e.g. http://www.foo.com");
        }

        foreach ($urls as $url) {
            if (!$this->sendRequest('PURGE', $this->domain . $url)) {
                return false;
            }
        }

        return true;
    }
504039
public function matches($url, array $annotations)
	{
		foreach ( $annotations as $annotation ) {
			if ( $url === $annotation->url ) {
				return true;
			}
		}

		return false;
	}
511674
private boolean isDomainInScope(String domain) {
		for (String scope : scopes) {
			if (domain.matches(scope)) {
				return true;
			}
		}
		return false;
	}