src/AbstractUrl.php
public static function createFromUrl($url)
    {
        $url = (string) $url;
        $url = trim($url);
        $original_url = $url;
        $url = self::sanitizeUrl($url);

        //if no valid scheme is found we add one
        if (is_null($url)) {
            throw new RuntimeException(sprintf('The given URL: `%s` could not be parse', $original_url));
        }

        $components = array_merge(array(
            'scheme' => null,
            'user' => null,
            'pass' => null,
            'host' => null,
            'port' => null,
            'path' => null,
            'query' => null,
            'fragment' => null,
        ), self::parseUrl($url));
        $components = self::formatAuthComponent($components);
        $components = self::formatPathComponent($components, $original_url);

        return new static(
            new Components\Scheme($components['scheme']),
            new Components\User($components['user']),
            new Components\Pass($components['pass']),
            new Components\Host($components['host']),
            new Components\Port($components['port']),
            new Components\Path($components['path']),
            new Components\Query($components['query']),
            new Components\Fragment($components['fragment'])
        );
    }
public static function createFromUrl($url)
    {
        $url = (string) $url;
        $url = trim($url);
        $original_url = $url;
        $url = self::sanitizeUrl($url);

        //if no valid scheme is found we add one
        if (is_null($url)) {
            throw new RuntimeException(sprintf('The given URL: `%s` could not be parse', $original_url));
        }

        $components = array_merge(array(
            'scheme' => null,
            'user' => null,
            'pass' => null,
            'host' => null,
            'port' => null,
            'path' => null,
            'query' => null,
            'fragment' => null,
        ), self::parseUrl($url));
        $components = self::formatAuthComponent($components);
        $components = self::formatPathComponent($components, $original_url);

        return new static(
            new Components\Scheme($components['scheme']),
            new Components\User($components['user']),
            new Components\Pass($components['pass']),
            new Components\Host($components['host']),
            new Components\Port($components['port']),
            new Components\Path($components['path']),
            new Components\Query($components['query']),
            new Components\Fragment($components['fragment'])
        );
    }
public static function createFromUrl ( $ url ) { $ url = ( string ) $ url ; $ url = trim ( $ url ) ; $ original_url = $ url ; $ url = self :: sanitizeUrl ( $ url ) ; //if no valid scheme is found we add one if ( is_null ( $ url ) ) { throw new RuntimeException ( sprintf ( 'The given URL: `%s` could not be parse' , $ original_url ) ) ; } $ components = array_merge ( array ( 'scheme' => null , 'user' => null , 'pass' => null , 'host' => null , 'port' => null , 'path' => null , 'query' => null , 'fragment' => null , ) , self :: parseUrl ( $ url ) ) ; $ components = self :: formatAuthComponent ( $ components ) ; $ components = self :: formatPathComponent ( $ components , $ original_url ) ; return new static ( new Components \ Scheme ( $ components [ 'scheme' ] ) , new Components \ User ( $ components [ 'user' ] ) , new Components \ Pass ( $ components [ 'pass' ] ) , new Components \ Host ( $ components [ 'host' ] ) , new Components \ Port ( $ components [ 'port' ] ) , new Components \ Path ( $ components [ 'path' ] ) , new Components \ Query ( $ components [ 'query' ] ) , new Components \ Fragment ( $ components [ 'fragment' ] ) ) ; }
Return a instance of Url from a string

@param string $url a string or an object that implement the __toString method

@return static

@throws RuntimeException If the URL can not be parse
Return a instance of Url from a string