public static function fromUrl($url, SslOptions $sslOptions = null)
    {
        $parsed = parse_url($url);
        
        // check it's a valid URL
        if (false === $parsed || !isset($parsed['host']) || !isset($parsed['scheme'])) {
            throw new \InvalidArgumentException("$url is not a valid URL");
        }
        
        // check it's http or https
        $scheme = strtolower($parsed['scheme']);
        if (!in_array($scheme, array('http', 'https'))) {
            throw new \InvalidArgumentException("$url is not a valid http/https URL");
        }

        // setup defaults
        $defaults = array('port' => 80, 'path' => '', 'user' => null, 'pass' => '');

        // change some defaults for https
        if ($scheme == 'https') {
            $sslOptions = $sslOptions ?: new SslOptions();
            $defaults['port'] = 443;
        }
         
        // merge defaults and real data and build transport
        $parsed = array_merge($defaults, $parsed);
        $transport = new static($parsed['host'], $parsed['port'], $parsed['path'], $sslOptions);

        // add optional authentication
        if ($parsed['user']) {
            $transport->setAuthentication($parsed['user'], $parsed['pass']);
        }

        return $transport;
    }