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;
    }
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;
    }
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 ; }
Creates a HttpTransport from a URI

Supports http and https schemes, port-, path- and auth-definitions
If the port is omitted 80 and 443 are used respectively.
If a username but no password is given, and empty password is used.
If a https URI is given, the provided SslOptions (with a fallback to
the default SslOptions) are used.

@param  string          $url
@param  SslOptions|null $sslOptions

@return HttpTransport
Creates a HttpTransport from a URI