src/Hostname.php
public static function fromParts(array $domainParts, ?string $tld = null): HostnameInterface
    {
        if (count($domainParts) === 0) {
            throw new HostnameInvalidArgumentException('Domain parts [] is empty.');
        }

        if (!self::myValidateDomainParts($domainParts, $error)) {
            throw new HostnameInvalidArgumentException('Domain parts ["' . implode('", "', $domainParts) . '"] is invalid: ' . $error);
        }

        if (!self::myValidateTld($tld, $error)) {
            throw new HostnameInvalidArgumentException($error);
        }

        self::myNormalizeDomainParts($domainParts);
        self::myNormalizeTld($tld);

        return new self($domainParts, $tld);
    }
public static function fromParts(array $domainParts, ?string $tld = null): HostnameInterface
    {
        if (count($domainParts) === 0) {
            throw new HostnameInvalidArgumentException('Domain parts [] is empty.');
        }

        if (!self::myValidateDomainParts($domainParts, $error)) {
            throw new HostnameInvalidArgumentException('Domain parts ["' . implode('", "', $domainParts) . '"] is invalid: ' . $error);
        }

        if (!self::myValidateTld($tld, $error)) {
            throw new HostnameInvalidArgumentException($error);
        }

        self::myNormalizeDomainParts($domainParts);
        self::myNormalizeTld($tld);

        return new self($domainParts, $tld);
    }
public static function fromParts ( array $ domainParts , ? string $ tld = null ) : HostnameInterface { if ( count ( $ domainParts ) === 0 ) { throw new HostnameInvalidArgumentException ( 'Domain parts [] is empty.' ) ; } if ( ! self :: myValidateDomainParts ( $ domainParts , $ error ) ) { throw new HostnameInvalidArgumentException ( 'Domain parts ["' . implode ( '", "' , $ domainParts ) . '"] is invalid: ' . $ error ) ; } if ( ! self :: myValidateTld ( $ tld , $ error ) ) { throw new HostnameInvalidArgumentException ( $ error ) ; } self :: myNormalizeDomainParts ( $ domainParts ) ; self :: myNormalizeTld ( $ tld ) ; return new self ( $ domainParts , $ tld ) ; }
Creates a hostname from hostname parts.

@since 1.0.0

@param string[]    $domainParts The domain parts.
@param string|null $tld         The top level domain or null if no top-level domain should be included.

@throws HostnameInvalidArgumentException If any of the parameters are invalid.
@throws \InvalidArgumentException        If the $domainParts parameter is not an array of strings.

@return HostnameInterface The hostname instance.
Creates a hostname from hostname parts .