private static function myParseAuthority(?UrlInterface $baseUrl = null, ?string $authorityString, ?HostInterface &$host = null, ?int &$port = null, ?string &$error = null): bool
    {
        if ($authorityString === null && $baseUrl !== null) {
            $host = $baseUrl->getHost();
            $port = $baseUrl->getPort();

            return true;
        }

        // Throw away username and password if present.
        $parts = explode('@', $authorityString, 2);
        if (count($parts) > 1) {
            $authorityString = $parts[1];
        }

        $parts = explode(':', $authorityString, 2);
        $port = null;

        // Try parse and validate port.
        if (count($parts) === 2 && $parts[1] !== '') {
            // Port containing invalid character is invalid.
            if (preg_match('/[^0-9]/', $parts[1], $matches)) {
                $error = 'Port "' . $parts[1] . '" contains invalid character "' . $matches[0] . '".';

                return false;
            }

            $port = intval($parts[1]);

            // Port out of range is invalid.
            if (!self::myValidatePort($port, $error)) {
                return false;
            }
        }

        try {
            $host = Host::parse($parts[0]);
        } catch (HostInvalidArgumentException $e) {
            $error = $e->getMessage();

            return false;
        }

        return true;
    }