Class Url
Parses and generates URLs based on URL parts. In favor of performance, URL parts are not validated.
Methods summary
-
public static
factory ( string $url )
Factory method to create a new URL from a URL string
-
public static
buildUrl ( array $parts )
Build a URL from parse_url parts. The generated URL will be a relative URL if a scheme or host are not provided.
-
public
__construct ( string $scheme, string $host, string $username = null, string $password = null, int $port = null, string $path = null, Guzzle\Http\QueryString $query = null, string $fragment = null )
Create a new URL from URL parts
-
public
__clone ( )
Clone the URL
-
public
__toString ( )
Returns the URL as a URL string
-
public
getParts ( )
Get the parts of the URL as an array
-
public
setHost ( string $host )
Set the host of the request.
-
public
getHost ( )
Get the host part of the URL
-
public
setScheme ( string $scheme )
Set the scheme part of the URL (http, https, ftp, etc)
-
public
getScheme ( )
Get the scheme part of the URL
-
public
setPort ( int $port )
Set the port part of the URL
-
public
getPort ( )
Get the port part of the URl. Will return the default port for a given scheme if no port has been set.
-
public
setPath ( array|string $path )
Set the path part of the URL
-
public
normalizePath ( )
Normalize the URL so that double slashes and relative paths are removed
-
public
addPath ( string $relativePath )
Add a relative path to the currently set path.
-
public
getPath ( )
Get the path part of the URL
-
public
getPathSegments ( )
Get the path segments of the URL as an array
-
public
setPassword ( string $password )
Set the password part of the URL
-
public
getPassword ( )
Get the password part of the URL
-
public
setUsername ( string $username )
Set the username part of the URL
-
public
getUsername ( )
Get the username part of the URl
-
public
getQuery ( )
Get the query part of the URL as a QueryString object
-
public
setQuery ( QueryString|string|array $query )
Set the query part of the URL
-
public
getFragment ( )
Get the fragment part of the URL
-
public
setFragment ( string $fragment )
Set the fragment part of the URL
-
public
isAbsolute ( )
Check if this is an absolute URL
-
public
combine ( string $url, bool $strictRfc3986 = false )
Combine the URL with another URL. Follows the rules specific in RFC 3986 section 5.4.
Methods detail
Factory method to create a new URL from a URL string
Parameters
- $url
string
$url Full URL used to create a Url object
Returns
Throws
Build a URL from parse_url parts. The generated URL will be a relative URL if a scheme or host are not provided.
Parameters
- $parts
array
$parts Array of parse_url parts
Returns
string
public
__construct( string $scheme, string $host, string $username = null, string $password = null, integer $port = null, string $path = null, Guzzle\Http\QueryString
$query = null, string $fragment = null )
Create a new URL from URL parts
Parameters
- $scheme
string
$scheme Scheme of the URL- $host
string
$host Host of the URL- $username
string
$username Username of the URL- $password
string
$password Password of the URL- $port
integer
$port Port of the URL- $path
string
$path Path of the URL- $query
Guzzle\Http\QueryString
|array|string
$query Query string of the URL- $fragment
string
$fragment Fragment of the URL
Clone the URL
Returns the URL as a URL string
Returns
string
Get the parts of the URL as an array
Returns
array
Set the host of the request.
Parameters
- $host
string
$host Host to set (e.g. www.yahoo.com, yahoo.com)
Returns
Get the host part of the URL
Returns
string
Set the scheme part of the URL (http, https, ftp, etc)
Parameters
- $scheme
string
$scheme Scheme to set
Returns
Get the scheme part of the URL
Returns
string
Get the port part of the URl. Will return the default port for a given scheme if no port has been set.
Returns
integer|null
Set the path part of the URL
Parameters
- $path
array|string
$path Path string or array of path segments
Returns
Add a relative path to the currently set path.
Parameters
- $relativePath
string
$relativePath Relative path to add
Returns
Get the path part of the URL
Returns
string
Get the path segments of the URL as an array
Returns
array
Set the password part of the URL
Parameters
- $password
string
$password Password to set
Returns
Get the password part of the URL
Returns
null|string
Set the username part of the URL
Parameters
- $username
string
$username Username to set
Returns
Get the username part of the URl
Returns
null|string
Set the query part of the URL
Parameters
- $query
Guzzle\Http\QueryString
|string|array
$query Query to set
Returns
Get the fragment part of the URL
Returns
null|string
Set the fragment part of the URL
Parameters
- $fragment
string
$fragment Fragment to set
Returns
Check if this is an absolute URL
Returns
boolean
Combine the URL with another URL. Follows the rules specific in RFC 3986 section 5.4.
Parameters
- $url
string
$url Relative URL to combine with- $strictRfc3986
boolean
$strictRfc3986 Set to true to use strict RFC 3986 compliance when merging paths. When first released, Guzzle used an incorrect algorithm for combining relative URL paths. In order to not break users, we introduced this flag to allow the merging of URLs based on strict RFC 3986 section 5.4.1. This means that "http://a.com/foo/baz" merged with "bar" would become "http://a.com/foo/bar". When this value is set to false, it would become "http://a.com/foo/baz/bar".
Returns
Throws
Link
Magic methods summary
Properties summary
protected
mixed
|
$scheme | |
protected
mixed
|
$host | |
protected
mixed
|
$port | |
protected
mixed
|
$username | |
protected
mixed
|
$password | |
protected
string
|
$path | |
protected
mixed
|
$fragment | |
protected
|
$query |
#
Query part of the URL |