Embedly\Embedly::parse_host PHP Method

parse_host() protected method

Returns an array of { protocol: , host: , port: , url: }
protected parse_host ( string $host ) : array
$host string
return array
    protected function parse_host($host)
    {
        $port = 80;
        $protocol = 'http';
        preg_match('/^(https?:\\/\\/)?([^\\/]+)(:\\d+)?\\/?$/', $host, $matches);
        if (!$matches) {
            throw new \Exception(sprintf('invalid host %s', $host));
        }
        $hostname = $matches[2];
        if ($matches[1] == 'https://') {
            $protocol = 'https';
        }
        if (array_key_exists(3, $matches) && $matches[3]) {
            $port = intval($matches[3]);
        } else {
            if ($matches[1] == 'https://') {
                $port = 443;
            }
        }
        $portpart = "";
        if (array_key_exists(3, $matches) && $matches[3]) {
            $portpart = sprintf(":%s", $matches[3]);
        }
        $url = sprintf("%s://%s%s/", $protocol, $hostname, $portpart);
        return array('url' => $url, 'scheme' => $protocol, 'hostname' => $hostname, 'port' => $port);
    }