Find the best matching active domain for the given hostname.

@param string $hostname Hostname the domain should match with (eg. "localhost" or "www.neos.io")
@param boolean $onlyActive Only include active domains
@return Domain
@api
772712
public function findOneByHost($hostname, $onlyActive = false)
    {
        $allMatchingDomains = $this->findByHost($hostname, $onlyActive);
        return count($allMatchingDomains) > 0 ? $allMatchingDomains[0] : null;
    }
975319
private boolean netscapeDomainMatches(final String domain, final String host) {
        if (domain == null || host == null) {
            return false;
        }

        // if there's no embedded dot in domain and domain is not .local
        boolean isLocalDomain = ".local".equalsIgnoreCase(domain);
        int embeddedDotInDomain = domain.indexOf('.');
        if (embeddedDotInDomain == 0) {
            embeddedDotInDomain = domain.indexOf('.', 1);
        }
        if (!isLocalDomain && (embeddedDotInDomain == -1 || embeddedDotInDomain == domain.length() - 1)) {
            return false;
        }

        // if the host name contains no dot and the domain name is .local
        int firstDotInHost = host.indexOf('.');
        if (firstDotInHost == -1 && isLocalDomain) {
            return true;
        }

        int domainLength = domain.length();
        int lengthDiff = host.length() - domainLength;
        if (lengthDiff == 0) {
            // if the host name and the domain name are just string-compare euqal
            return host.equalsIgnoreCase(domain);
        }
        else if (lengthDiff > 0) {
            // need to check H & D component
            String H = host.substring(0, lengthDiff);
            String D = host.substring(lengthDiff);

            return (D.equalsIgnoreCase(domain));
        }
        else if (lengthDiff == -1) {
            // if domain is actually .host
            return (domain.charAt(0) == '.' &&
                    host.equalsIgnoreCase(domain.substring(1)));
        }

        return false;
    }
957530
public function findOneByDomainName(string $domainName): array
    {
        $queryBuilder = $this->createQuery();

        return (array)$queryBuilder->select('*')
            ->from($this->getTableName())
            ->where($queryBuilder->expr()->eq(
                'domainName',
                $queryBuilder->createNamedParameter($domainName, \PDO::PARAM_STR)
            ))
            ->execute()
            ->fetch();
    }
1143198
public function getServerByHostname(string $hostname): Server
    {
        if (!isset($this->servers[$hostname])) {
            throw ClusterException::serverNotFound($hostname);
        }

        return $this->servers[$hostname];
    }
507858
static function getByName(string $hostname): IPAddress {
        $host = gethostbyname($hostname);
        if ($host === $hostname) {
            throw new \InvalidArgumentException($hostname);
        }
        return new self($host);
    }
1354562
def match_host (host, domainlist):
    """"""
    if not host:
        return False
    for domain in domainlist:
        if domain.startswith('.'):
            if host.endswith(domain):
                return True
        elif host == domain:
            return True
    return False
1216962
public static function matches($providedDomain=null)
	{
		if (strtolower(php_sapi_name()) == 'cli') {
			return true;
		}

		if (is_string($providedDomain)) {
			return $_SERVER['HTTP_HOST'] == $providedDomain;
		}

		if (is_array($providedDomain)) {
			if (in_array($_SERVER['HTTP_HOST'], $providedDomain)) {
				return true;
			}
		}

		return false;
	}
345703
public function getRemoteHostname() {
        static $hostname = null;
        if (!$hostname) {
            /** @var string $hostname */
            $hostname = NetTools::getHostByAddress($this->getRemoteAddress());
        }
        return $hostname;
    }
364632
public function activateCommand($hostname)
    {
        $domains = $this->findDomainsByHostnamePattern($hostname);
        if (empty($domains)) {
            $this->outputLine('<error>No domain found for hostname-pattern "%s".</error>', [$hostname]);
            $this->quit(1);
        }
        foreach ($domains as $domain) {
            $domain->setActive(true);
            $this->domainRepository->update($domain);
            $this->outputLine('Domain entry "%s" was activated.', [$domain->getHostname()]);
        }
    }
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));
    }
993953
private function decodeHost($hostname)
    {
        if (preg_match('/^[\\x00-\\x7F]*$/', $hostname)) {
            return $hostname;
        } elseif ($this->mode !== self::MODE_IDNA2003) {
            throw new \InvalidArgumentException("Invalid hostname '$hostname'");
        }

        $hostname = idn_to_ascii($hostname);

        if ($hostname === false) {
            throw new \InvalidArgumentException("Invalid hostname '$hostname'");
        }

        return $hostname;
    }
1034877
public function deactivateCommand($hostname)
    {
        $domains = $this->findDomainsByHostnamePattern($hostname);
        if (empty($domains)) {
            $this->outputLine('<error>No domain found for hostname-pattern "%s".</error>', [$hostname]);
            $this->quit(1);
        }
        foreach ($domains as $domain) {
            $domain->setActive(false);
            $this->domainRepository->update($domain);
            $this->outputLine('Domain entry "%s" was deactivated.', [$domain->getHostname()]);
        }
    }
1181509
public static function isHostnameIP($hostname)
  {
    // IP-literal: encased in square brackets
    // we match starting [ character followed by non ] characters followed by ] character as last character in hostname
    if(preg_match('/^\[[^\]]\]$/',$hostname)){
      // ok its an IP-literal, we do not parse the literal to see if its valid
      return true;
    }
    // IPv4 in decimal
    if(preg_match('/^[0-9]+$/',$hostname)){
      // ok its a number
      // lets see if its in the 32bit range
      $ip4_hex=base_convert($hostname, 10, 16);
      if(strlen($ip4_hex)<=8){
        // ok, hex representation is less than 9 chars, so thats max FFFFFFFF
        return true;
      }
    }
    $ip_parts=Array();
    if(!preg_match('/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/',$hostname,$ip_parts)){
      return false;
    }
    // check if each block is in byte range (hard to test with regex)
    for($j=1;$j<=4;$j++){
      if(($ip_parts[$j]>255) || ($ip_parts[$j]<0)){
        return false;
      }
    }
    return true;
  }
493145
public function hostMatches($host)
    {
        $pattern = '@^' . str_replace('\*', '.*', preg_quote($this->options['_host'], '@')) . '$@';

        return preg_match($pattern, $host) !== 0;
    }
300088
protected function resolveHostname($hostname)
    {
        if (false !== filter_var($hostname, FILTER_VALIDATE_IP)) {
            return \React\Promise\resolve($hostname);
        }

        return $this->getResolver()->resolve($hostname);
    }
339025
public function getDomain($domainName)
    {
        if (isset($this->domainMap[$domainName])) {
            return $this->domainMap[$domainName];
        }

        return null; // just to be explicit
    }
543830
public function getDomainByName($domainName, $default = null)
    {
        if (empty($domainName)) {
            return $default;
        }

        try {
            $result = $this->findOneBy(['domain' => $domainName]);
        } catch (NoResultException $e) {
            $result = $default;
        }

        return $result;
    }