TYPO3  7.6
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
Net_URL2 Class Reference

Public Member Functions

 __construct ($url, array $options=array())
 
 __set ($var, $arg)
 
 __get ($var)
 
 getScheme ()
 
 setScheme ($scheme)
 
 getUser ()
 
 getPassword ()
 
 getUserinfo ()
 
 setUserinfo ($userinfo, $password=false)
 
 getHost ()
 
 setHost ($host)
 
 getPort ()
 
 setPort ($port)
 
 getAuthority ()
 
 setAuthority ($authority)
 
 getPath ()
 
 setPath ($path)
 
 getQuery ()
 
 setQuery ($query)
 
 getFragment ()
 
 setFragment ($fragment)
 
 getQueryVariables ()
 
 setQueryVariables (array $array)
 
 setQueryVariable ($name, $value)
 
 unsetQueryVariable ($name)
 
 getURL ()
 
 __toString ()
 
 getNormalizedURL ()
 
 normalize ()
 
 isAbsolute ()
 
 resolve ($reference)
 
 getOption ($optionName)
 

Static Public Member Functions

static removeDotSegments ($path)
 
static urlencode ($string)
 
static getCanonical ()
 
static getRequestedURL ()
 
static getRequested ()
 

Public Attributes

const OPTION_STRICT = 'strict'
 
const OPTION_USE_BRACKETS = 'use_brackets'
 
const OPTION_DROP_SEQUENCE = 'drop_sequence'
 
const OPTION_ENCODE_KEYS = 'encode_keys'
 
const OPTION_SEPARATOR_INPUT = 'input_separator'
 
const OPTION_SEPARATOR_OUTPUT = 'output_separator'
 

Protected Member Functions

 buildQuery (array $data, $separator, $key=null)
 
 parseUrl ($url)
 

Private Member Functions

 _queryArrayByKey ($key, $value, array $array=array())
 
 _queryArrayByBrackets ($buffer, $value, array $array=null)
 
 _queryKeyBracketOffset ($key)
 
 _buildAuthorityAndPath ($authority, $path)
 
 _normalize ($mixed)
 
 _normalizeCallback ($matches)
 
 _isFragmentOnly ()
 
 _encodeData ($url)
 
 _encodeCallback (array $matches)
 

Private Attributes

 $_options
 
 $_scheme = false
 
 $_userinfo = false
 
 $_host = false
 
 $_port = false
 
 $_path = ''
 
 $_query = false
 
 $_fragment = false
 

Detailed Description

Definition at line 57 of file URL2.php.

Constructor & Destructor Documentation

__construct (   $url,
array  $options = array() 
)

Constructor.

Parameters
string$urlan absolute or relative URL
array$optionsan array of OPTION_xxx constants

self::parseUrl()

Definition at line 148 of file URL2.php.

References $url, and parseUrl().

Member Function Documentation

__get (   $var)

Magic Getter.

This is the magic get method to retrieve the private variable that was set by either __set() or it's setter...

Parameters
string$varThe property name to retrieve.
Returns
mixed $this->$var Either a boolean false if the property is not set or the value of the private property.

Definition at line 190 of file URL2.php.

__set (   $var,
  $arg 
)

Magic Setter.

This method will magically set the value of a private variable ($var) with the value passed as the args

Parameters
string$varThe private variable to set.
mixed$argAn argument of any type.
Returns
void

Definition at line 170 of file URL2.php.

__toString ( )

Returns a string representation of this URL.

Returns
string https://php.net/language.oop5.magic#object.tostring

Definition at line 752 of file URL2.php.

References getURL().

Referenced by HTTP_Request2\send().

_buildAuthorityAndPath (   $authority,
  $path 
)
private

Put authority and path together, wrapping authority into proper separators/terminators.

Parameters
string | bool$authorityauthority
string$pathpath
Returns
string

Definition at line 735 of file URL2.php.

Referenced by getURL().

_encodeCallback ( array  $matches)
private

callback for encoding character data

Parameters
array$matchesMatches
Returns
string
See Also
_encodeData (PHPMD.UnusedPrivateMethod)

Definition at line 1215 of file URL2.php.

_encodeData (   $url)
private

Encode characters that might have been forgotten to encode when passing in an URL. Applied onto Userinfo, Path and Query.

Parameters
string$urlURL
Returns
string
See Also
parseUrl
setAuthority https://pear.php.net/bugs/bug.php?id=20425

Definition at line 1198 of file URL2.php.

References $url.

Referenced by parseUrl(), setAuthority(), and setUserinfo().

_isFragmentOnly ( )
private

URL is fragment-only

(PHPMD.UnusedPrivateMethod)

Returns
bool

Definition at line 955 of file URL2.php.

_normalize (   $mixed)
private

Normalize case of XX percentage-encodings (RFC 3986, section 6.2.2.1) Normalize percentage-encoded unreserved characters (section 6.2.2.2)

Parameters
string | array$mixedstring or array of strings to normalize
Returns
string|array
See Also
normalize
_normalizeCallback()

Definition at line 840 of file URL2.php.

Referenced by normalize().

_normalizeCallback (   $matches)
private

Callback for _normalize() of XX percentage-encodings

Parameters
array$matchesas by preg_replace_callback
Returns
string
See Also
normalize
_normalize (PHPMD.UnusedPrivateMethod)

Definition at line 858 of file URL2.php.

_queryArrayByBrackets (   $buffer,
  $value,
array  $array = null 
)
private

Parse a key-buffer to place value in array

Parameters
string$bufferto consume all keys from
string$valueto be set/add
array$arrayto traverse and set/add value in
Exceptions
Exception
Returns
array

Definition at line 572 of file URL2.php.

References _queryKeyBracketOffset().

Referenced by _queryArrayByKey().

_queryArrayByKey (   $key,
  $value,
array  $array = array() 
)
private

Parse a single query key=value pair into an existing php array

Parameters
string$keyquery-key
string$valuequery-value
array$arrayof existing query variables (if any)
Returns
mixed

Definition at line 528 of file URL2.php.

References _queryArrayByBrackets(), and _queryKeyBracketOffset().

Referenced by getQueryVariables().

_queryKeyBracketOffset (   $key)
private

Query-key has brackets ("...[]")

Parameters
string$keyquery-key
Returns
bool|int offset of opening bracket, false if no brackets

Definition at line 633 of file URL2.php.

Referenced by _queryArrayByBrackets(), and _queryArrayByKey().

buildQuery ( array  $data,
  $separator,
  $key = null 
)
protected

A simple version of http_build_query in userland. The encoded string is percentage encoded according to RFC 3986.

Parameters
array$dataAn array, which has to be converted into QUERY_STRING. Anything is possible.
string$separatorSeparator self::OPTION_SEPARATOR_OUTPUT
string$keyFor stacked values (arrays in an array).
Returns
string

Definition at line 1128 of file URL2.php.

References getOption().

Referenced by setQueryVariables().

getAuthority ( )

Returns the authority part, i.e. [ userinfo "@" ] host [ ":" port ], or false if there is no authority.

Returns
string|bool

Definition at line 346 of file URL2.php.

References $_host, and $_port.

Referenced by getURL(), normalize(), and resolve().

static getCanonical ( )
static

Returns a Net_URL2 instance representing the canonical URL of the currently executing PHP script.

Exceptions
Exception
Returns
string

Definition at line 1052 of file URL2.php.

References $url.

getFragment ( )

Returns the fragment name, or false if "#" is not present in the URL.

Returns
string|bool

Definition at line 459 of file URL2.php.

References $_fragment.

getHost ( )

Returns the host part, or false if there is no authority part, e.g. relative URLs.

Returns
string|bool a hostname, an IP address, or false

Definition at line 296 of file URL2.php.

References $_host.

Referenced by HTTP_Request2_CookieJar\getMatching().

getNormalizedURL ( )

Returns a normalized string representation of this URL. This is useful for comparison of URLs.

Returns
string

Definition at line 763 of file URL2.php.

References $url.

getOption (   $optionName)

Returns the value of the specified option.

Parameters
string$optionNameThe name of the option to retrieve
Returns
mixed

Definition at line 1111 of file URL2.php.

Referenced by buildQuery(), getQueryVariables(), resolve(), and setQueryVariables().

getPassword ( )

Returns the password part of the userinfo part (the part after the first ":"), or false if there is no userinfo part (i.e. the URL does not contain "@" in front of the hostname) or the userinfo part does not contain ":".

Returns
string|bool

Definition at line 249 of file URL2.php.

getPath ( )

Returns the path part (possibly an empty string).

Returns
string

Definition at line 409 of file URL2.php.

References $_path.

Referenced by HTTP_Request2_CookieJar\getMatching().

getPort ( )

Returns the port number, or false if there is no port number specified, i.e. if the default port is to be used.

Returns
string|bool

Definition at line 321 of file URL2.php.

References $_port.

getQuery ( )

Returns the query string (excluding the leading "?"), or false if "?" is not present in the URL.

Returns
string|bool
See Also
getQueryVariables

Definition at line 434 of file URL2.php.

References $_query.

getQueryVariables ( )

Returns the query string like an array as the variables would appear in $_GET in a PHP script. If the URL does not contain a "?", an empty array is returned.

Returns
array

Definition at line 485 of file URL2.php.

References _queryArrayByKey(), and getOption().

Referenced by setQueryVariable(), and unsetQueryVariable().

static getRequested ( )
static

Returns a Net_URL2 instance representing the URL used to retrieve the current request.

Exceptions
Exception
Returns
$this

Definition at line 1089 of file URL2.php.

References $url.

static getRequestedURL ( )
static

Returns the URL used to retrieve the current request.

Returns
string

Definition at line 1077 of file URL2.php.

getScheme ( )

Returns the scheme, e.g. "http" or "urn", or false if there is no scheme specified, i.e. if this is a relative URL.

Returns
string|bool

Definition at line 206 of file URL2.php.

References $_scheme.

Referenced by HTTP_Request2_CookieJar\getMatching().

getURL ( )

Returns a string representation of this URL.

Returns
string

Definition at line 699 of file URL2.php.

References $_fragment, $_query, $url, _buildAuthorityAndPath(), and getAuthority().

Referenced by __toString().

getUser ( )

Returns the user part of the userinfo part (the part preceding the first ":"), or false if there is no userinfo part.

Returns
string|bool

Definition at line 234 of file URL2.php.

getUserinfo ( )

Returns the userinfo part, or false if there is none, i.e. if the authority part does not contain "@".

Returns
string|bool

Definition at line 262 of file URL2.php.

References $_userinfo.

isAbsolute ( )

Returns whether this instance represents an absolute URL.

Returns
bool

Definition at line 868 of file URL2.php.

References $_scheme.

Referenced by resolve(), and HTTP_Request2\send().

normalize ( )

Normalizes the URL

See RFC 3986, Section 6. Normalization and Comparison

void

Definition at line 779 of file URL2.php.

References $_path, _normalize(), and getAuthority().

parseUrl (   $url)
protected

This method uses a regex to parse the url into the designated parts.

Parameters
string$urlURL
Returns
void self::$_scheme, self::setAuthority(), self::$_path, self::$_query, self::$_fragment
See Also
__construct

Definition at line 1166 of file URL2.php.

References $url, _encodeData(), and setAuthority().

Referenced by __construct().

static removeDotSegments (   $path)
static

Removes dots as described in RFC 3986, section 5.2.4, e.g. "/foo/../bar/baz" => "/bar/baz"

Parameters
string$patha path
Returns
string a path

Definition at line 976 of file URL2.php.

References elseif.

resolve (   $reference)

Returns an Net_URL2 instance representing an absolute URL relative to this URL.

Parameters
Net_URL2 | string$referencerelative URL
Exceptions
Exception
Returns
$this

Definition at line 882 of file URL2.php.

References $_path, $_query, $_scheme, getAuthority(), getOption(), and isAbsolute().

Referenced by HTTP_Request2_Adapter_Curl\callbackWriteHeader().

setAuthority (   $authority)

Sets the authority part, i.e. [ userinfo "@" ] host [ ":" port ]. Specify false if there is no authority.

Parameters
string | bool$authoritya hostname or an IP address, possibly with userinfo prefixed and port number appended, e.g. "foo:bar@example.org:81".
Returns
$this

Definition at line 377 of file URL2.php.

References _encodeData().

Referenced by parseUrl().

setFragment (   $fragment)

Sets the fragment name. Specify false if "#" is not present in the URL.

Parameters
string | bool$fragmenta fragment excluding the leading "#", or false
Returns
$this

Definition at line 472 of file URL2.php.

setHost (   $host)

Sets the host part. Specify false if there is no authority part, e.g. relative URLs.

Parameters
string | bool$hosta hostname, an IP address, or false
Returns
$this

Definition at line 309 of file URL2.php.

setPath (   $path)

Sets the path part (possibly an empty string).

Parameters
string$patha path
Returns
$this

Definition at line 421 of file URL2.php.

setPort (   $port)

Sets the port number. Specify false if there is no port number specified, i.e. if the default port is to be used.

Parameters
string | bool$porta port number, or false
Returns
$this

Definition at line 334 of file URL2.php.

setQuery (   $query)

Sets the query string (excluding the leading "?"). Specify false if "?" is not present in the URL.

Parameters
string | bool$querya query string, e.g. "foo=1&bar=2"
Returns
$this
See Also
setQueryVariables

Definition at line 448 of file URL2.php.

setQueryVariable (   $name,
  $value 
)

Sets the specified variable in the query string.

Parameters
string$namevariable name
mixed$valuevariable value
Returns
$this

Definition at line 672 of file URL2.php.

References getQueryVariables(), and setQueryVariables().

setQueryVariables ( array  $array)

Sets the query string to the specified variable in the query string.

Parameters
array$array(name => value) array
Returns
$this

Definition at line 651 of file URL2.php.

References buildQuery(), and getOption().

Referenced by setQueryVariable(), and unsetQueryVariable().

setScheme (   $scheme)

Sets the scheme, e.g. "http" or "urn". Specify false if there is no scheme specified, i.e. if this is a relative URL.

Parameters
string | bool$schemee.g. "http" or "urn", or false if there is no scheme specified, i.e. if this is a relative URL
Returns
$this
See Also
getScheme

Definition at line 222 of file URL2.php.

setUserinfo (   $userinfo,
  $password = false 
)

Sets the userinfo part. If two arguments are passed, they are combined in the userinfo part as username ":" password.

Parameters
string | bool$userinfouserinfo or username
string | bool$passwordoptional password, or false
Returns
$this

Definition at line 276 of file URL2.php.

References _encodeData().

unsetQueryVariable (   $name)

Removes the specified variable from the query string.

Parameters
string$namea query string variable, e.g. "foo" in "?foo=1"
Returns
void

Definition at line 687 of file URL2.php.

References getQueryVariables(), and setQueryVariables().

static urlencode (   $string)
static

Percent-encodes all non-alphanumeric characters except these: _ . - ~ Similar to PHP's rawurlencode(), except that it also encodes ~ in PHP 5.2.x and earlier.

Parameters
string$stringstring to encode
Returns
string

Definition at line 1036 of file URL2.php.

References $encoded.

Member Data Documentation

$_fragment = false
private

Definition at line 138 of file URL2.php.

Referenced by getFragment(), and getURL().

$_host = false
private

Definition at line 118 of file URL2.php.

Referenced by getAuthority(), and getHost().

$_options
private
Initial value:
= array(
self::OPTION_STRICT => true,
self::OPTION_USE_BRACKETS => true,
self::OPTION_DROP_SEQUENCE => true,
self::OPTION_ENCODE_KEYS => true,
self::OPTION_SEPARATOR_INPUT => '&',
self::OPTION_SEPARATOR_OUTPUT => '&',
)

Default options corresponds to how PHP handles $_GET.

Definition at line 96 of file URL2.php.

$_path = ''
private

Definition at line 128 of file URL2.php.

Referenced by getPath(), normalize(), and resolve().

$_port = false
private

Definition at line 123 of file URL2.php.

Referenced by getAuthority(), and getPort().

$_query = false
private

Definition at line 133 of file URL2.php.

Referenced by getQuery(), getURL(), and resolve().

$_scheme = false
private

Definition at line 108 of file URL2.php.

Referenced by getScheme(), isAbsolute(), and resolve().

$_userinfo = false
private

Definition at line 113 of file URL2.php.

Referenced by getUserinfo().

const OPTION_DROP_SEQUENCE = 'drop_sequence'

Drop zero-based integer sequences in query using PHP's [] notation. Default is true.

Definition at line 74 of file URL2.php.

const OPTION_ENCODE_KEYS = 'encode_keys'

URL-encode query variable keys. Default is true.

Definition at line 79 of file URL2.php.

const OPTION_SEPARATOR_INPUT = 'input_separator'

Query variable separators when parsing the query string. Every character is considered a separator. Default is "&".

Definition at line 85 of file URL2.php.

const OPTION_SEPARATOR_OUTPUT = 'output_separator'

Query variable separator used when generating the query string. Default is "&".

Definition at line 91 of file URL2.php.

const OPTION_STRICT = 'strict'

Do strict parsing in resolve() (see RFC 3986, section 5.2.2). Default is true.

Definition at line 63 of file URL2.php.

const OPTION_USE_BRACKETS = 'use_brackets'

Represent arrays in query using PHP's [] notation. Default is true.

Definition at line 68 of file URL2.php.

Referenced by HTTP_Request2_Adapter_Socket\handleRedirect(), and HTTP_Request2\setUrl().