private function parseEndpoint()

in src/Apache/Ignite/ClientConfiguration.php [257:293]


    private function parseEndpoint(string $endpoint): string
    {
        $endpoint = trim($endpoint);
        $host = $endpoint;
        $port = null;
        $parsed = explode(':', $endpoint);
        if (count($parsed) > 2) {
            // IPv6 address
            $index = strrpos($endpoint, ']:');
            if ($index !== false) {
                $host = substr($endpoint, 0, $index + 1);
                $port = substr($endpoint, $index + 2);
            }
            $first = $host[0];
            $last = $host[strlen($host) - 1];
            if ($first === '[' || $last === ']') {
                if (!($first === '[' && $last === ']')) {
                    ArgumentChecker::illegalArgument('Incorrect endpoint format: ' . $endpoint);
                }
            } else {
                $host = sprintf('[%s]', $host);
            }
        }
        else {
            // IPv4 address
            $host = $parsed[0];
            if (count($parsed) === 2) {
                $port = $parsed[1];
            }
        }
        if ($port === null) {
            $port = self::ENDPOINT_PORT_DEFAULT;
        } elseif (!ctype_digit($port)) {
            ArgumentChecker::illegalArgument('Incorrect endpoint format: ' . $endpoint);
        }
        return sprintf('%s:%s', $host, $port);
    }