Extracts subdomain, host and suffix from input string. Based on algorithm described in
https://publicsuffix.org/list/.

@param string $hostname Hostname for extraction

@return array|string[] An array that contains subdomain, host and suffix.
187316
public function extractParts($hostname)
    {
        $suffix = $this->extractSuffix($hostname);

        if ($suffix === $hostname) {
            return [null, $hostname, null];
        }

        if (null !== $suffix) {
            $hostname = Str::substr($hostname, 0, -Str::length($suffix) - 1);
        }

        $lastDot = Str::strrpos($hostname, '.');

        if (false === $lastDot) {
            return [null, $hostname, $suffix];
        }

        $subDomain = Str::substr($hostname, 0, $lastDot);
        $host = Str::substr($hostname, $lastDot + 1);

        return [
            $subDomain,
            $host,
            $suffix
        ];
    }
1077544
public function extractHostname( $uri )
    {
        $hostname = false;

        $parts = parse_url( $uri );

        if ( isset( $parts['host'] ) )
            $hostname = $parts['host'];

        return $hostname;
    }
1012087
public function getSubdomains()
    {
        $current = $this->server['HTTP_HOST'];
        $parts = explode('.', $current);

        // two steps back
        array_pop($parts);
        array_pop($parts);

        return $parts;
    }
962788
public function setHostname(string $hostname)
    {
        $this->hostname = $hostname;

        $this->raw = array_merge($this->raw, ['Hostname' => $hostname]);

        return $this;
    }
1329581
public function isHost(string $host, bool $includeSubDomains = false) : bool
    {
        $thisHost = strtolower($this->host);
        $thatHost = strtolower($host);

        if (! $includeSubDomains) {
            return $thisHost === $thatHost;
        }

        $thisHost = explode('.', $thisHost);
        $thatHost = explode('.', $thatHost);

        return array_slice($thisHost, - count($thatHost)) === $thatHost;
    }
146387
public static function redisKey($host = null, $suffix = null)
    {
        if (is_null($host)) {
            return 'hosts';
        }

        $hostname = $host instanceof Host ? $host->hostname : $host;
        return 'host:'.$hostname.($suffix ? ':'.$suffix : '');
    }
843963
public function callback(string $hostname)
    {
        return function ($type, $buffer) use ($hostname) {
            foreach (explode("\n", rtrim($buffer)) as $line) {
                $this->writeln($type, $hostname, $line);
            }
        };
    }
114297
public function getAll($domainName)
    {
        $domainRecords = $this->adapter->get(sprintf('%s/domains/%s/records?per_page=%d', $this->endpoint, $domainName, 200));

        $domainRecords = json_decode($domainRecords);

        $this->extractMeta($domainRecords);

        return array_map(function ($domainRecord) {
            return new DomainRecordEntity($domainRecord);
        }, $domainRecords->domain_records);
    }
919615
public function listeners(string $eventName): array
    {
        if (!\array_key_exists($eventName, $this->listenerIndex)) {
            // Create a new index.
            $listeners = [];
            $listenersPriority = [];
            if (isset($this->listeners[$eventName])) {
                foreach ($this->listeners[$eventName] as $listener) {
                    $listenersPriority[] = $listener[0];
                    $listeners[] = $listener[1];
                }
            }

            foreach ($this->wildcardListeners as $wcEvent => $wcListeners) {
                // Wildcard match
                if (\substr($eventName, 0, \strlen($wcEvent)) === $wcEvent) {
                    foreach ($wcListeners as $listener) {
                        $listenersPriority[] = $listener[0];
                        $listeners[] = $listener[1];
                    }
                }
            }

            // Sorting by priority
            \array_multisort($listenersPriority, SORT_NUMERIC, $listeners);

            // Creating index
            $this->listenerIndex[$eventName] = $listeners;
        }

        return $this->listenerIndex[$eventName];
    }
1267745
public function getHostGroupsByHost(Host $host)
    {
        return array_values(
            array_filter(
                $this->hostGroups,
                function ($g) use ($host) {
                    return $g->hasHost($host);
                }
            )
        );
    }
828691
public function equals(HostnameInterface $hostname): bool
    {
        return $this->getDomainParts() === $hostname->getDomainParts() && $this->getTld() === $hostname->getTld();
    }
188186
public static function extractHeadersAndBodyStartOffset($input)
    {
        self::_setup($input);

        if (self::PROCMODE_FILE === self::$_mode)
            self::_processFile();
        else if (self::PROCMODE_STRING === self::$_mode)
            self::_processString();
        else
            throw new \DomainException('CURLHeaderExtractor - Invalid state');

        return array(self::$_headers, self::$_bodyStartByteOffset);
    }
486863
public static function parse_host_parts($host) {
		// Tease out the hostname.
		if (false === ($host = static::parse_host($host))) {
			return false;
		}

		$out = static::HOST_PARTS;

		// If this is an IP, we don't have to do anything else.
		if (\filter_var($host, \FILTER_VALIDATE_IP)) {
			$out['host'] = $host;
			$out['domain'] = $host;
			return $out;
		}

		// Now the hard part. See if any parts of the host
		// correspond to a registered suffix.
		$suffixes = data::SUFFIXES;
		$suffix = array();
		$parts = \explode('.', $host);
		$parts = \array_reverse($parts);

		foreach ($parts as $k=>$part) {
			// Override rule.
			if (isset($suffixes[$part], $suffixes[$part]['!'])) {
				break;
			}

			// A match.
			if (isset($suffixes[$part])) {
				\array_unshift($suffix, $part);
				$suffixes = $suffixes[$part];
				unset($parts[$k]);
				continue;
			}

			// A wildcard.
			if (isset($suffixes['*'])) {
				\array_unshift($suffix, $part);
				$suffixes = $suffixes['*'];
				unset($parts[$k]);
				continue;
			}

			// We're done.
			break;
		}

		// The suffix can't be all there is.
		if (! \count($parts)) {
			return false;
		}

		// The domain.
		$parts = \array_reverse($parts);
		$out['domain'] = \array_pop($parts);

		// The subdomain.
		if (\count($parts)) {
			$out['subdomain'] = \implode('.', $parts);
		}

		// The suffix.
		if (\count($suffix)) {
			$out['suffix'] = \implode('.', $suffix);
		}

		$out['host'] = $host;

		return $out;
	}
495492
protected function setHost($hostname) {
        if (!is_string($hostname)) throw new IllegalTypeException('Illegal type of parameter $hostname: '.gettype($hostname));
        if (!strlen($hostname))    throw new InvalidArgumentException('Invalid parameter $hostname: "'.$hostname.'" (empty)');

        $host = $hostname;
        $port = null;

        if (strpos($host, ':') !== false) {
            list($host, $port) = explode(':', $host, 2);
            $host = trim($host);
            if (!strlen($host)) throw new InvalidArgumentException('Invalid parameter $hostname: "'.$hostname.'" (empty host name)');

            $port = trim($port);
            if (!ctype_digit($port)) throw new InvalidArgumentException('Invalid parameter $hostname: "'.$hostname.'" (not a port)');
            $port = (int) $port;
            if (!$port || $port > 65535) throw new InvalidArgumentException('Invalid parameter $hostname: "'.$hostname.'" (illegal port)');
        }

        $this->host = $host;
        $this->port = $port;
        return $this;
    }
578934
public function withSubDomain($subDomain)
    {
        $uri = clone $this;

        if (is_null($subDomain)) {
            $uri->subDomain = null;
            $uri->subDomains = [];
        } elseif (is_string($subDomain)) {
            $uri->subDomain = $subDomain;
            $uri->subDomains = [$subDomain];
        } elseif (is_array($subDomain)) {
            $uri->subDomain = reset($subDomain);
            $uri->subDomains = $subDomain;
        }

        $uri->subDomains = array_unique($uri->subDomains);
        $this->setOrdinalKeys($uri->subDomains, count($uri->subDomains) + 2);

        return $uri;
    }
1237561
protected function isValidDomain($hostname)
    {
        return preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $hostname)
            && preg_match("/^.{1,253}$/", $hostname)
            && preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $hostname)
            && !preg_match("/^\d{0,3}\.\d{0,3}\.\d{0,3}\.\d{0,3}$/", $hostname);
    }
1175673
private function formatHost(?string $host): ?string
    {
        if (null === $host || '' === $host) {
            return $host;
        }

        if ('[' !== $host[0]) {
            return $this->formatRegisteredName($host);
        }

        return $this->formatIp($host);
    }