SPHPlayground API
SPHPlayground
sphplayground sphplayground

URL related components

Uniform Resource Locator (URL)

A Uniform Resource Locator (URL) is a reference to a resource that specifies its location on a computer network and a mechanism for retrieving it. Every HTTP URL conforms to the syntax of a generic URI.[1] The generic URI syntax consists of a hierarchical sequence of components referred to as the scheme, authority, path, query, and fragment. [2]

URI = scheme ":" ["//" authority ] path ["?" query ] ["#" fragment ]
authority = [ userinfo "@"] host [":" port ]
userinfo = user ":" pass

URL component manipulation:

  1. scheme: scheme - e.g. http(s)
    URL::getScheme() | URL::setScheme() | URL::containsScheme()
  2. authority: optional component
    1. userinfo: An optional userinfo subcomponent. Providing user information directly in HTTP URLs is not recommended. Use other methods to avoid for example semantic URL attacks. [3]
      1. user: optional component
        URL::getUsername() | URL::setUsername() | URL::containsUsername()
      2. pass: optional component
        URL::getPassword() | URL::setPassword() | URL::containsPassword()
    2. host: A host subcomponent, consisting of either a registered name (including but not limited to a hostname) or an IP address. [4]
      URL::getHost() | URL::setHost() | URL::containsHost()
    3. port: An optional port subcomponent
      URL::getPort() | URL::setPort() | URL::containsPort()
  3. path: A path component, consisting of a sequence of path segments separated by a slash
    URL::getPath() | URL::setPath() | URL::containsPath()
  4. query: An optional query component impemented by QueryString
  5. fragment: An optional fragment component
    URL::getFragment() | URL::setFragment() | URL::containsFragment()
Synopsis
Constructor
final public __construct(?string $url = null)
Clones the object
public __clone()
Sets the userinfo component
public setUsername(?string $username):static
Sets the path component
public setPassword(?string $password):static
Sets the path component
public setPath(?string $path):static
Sets the fragment component
public setFragment(?string $fragment):static
Sets the scheme component
public setScheme(?string $scheme):static
Returns the scheme name of the URL
public getScheme():?string
Checks if the scheme component is set
public containsScheme():bool
Sets the host component
public setHost(?string $host):static
Returns the host component
public getHost():?string
Checks if the host component is set
public containsHost():bool
Checks if the URL is IPv6
public isIPv6():bool
Returns the user component
public getUsername():?string
Checks if the user part of the URL is set
public containsUsername():bool
Returns the fragment component
public getPassword():?string
Checks if the password component of the URL is set
public containsPassword():bool
Returns the path component of the URL
public getPath():?string
Checks if the path component of the URL is set
public containsPath():bool
Sets the query component of the URL
public setQuery(Traversable|array|string|null $query):static
Returns the query string object of the URL
public getQuery():QueryString
Checks if the query part of the URL is set
public containsQuery():bool
Sets the port subcomponent
public setPort(?int $port):static
Returns the port number associated with this service and a given protocol
public resolvePort():?int
Returns the port number associated with this service and a given protocol
public getPort():?int
Returns the authority component
public getAuthority():string
public containsAuthority():bool
Checks if the port part of the URL is set
public containsPort():bool
Returns the port number associated with this service and a given protocol
public hasDefaultPort():bool
Returns the fragment component
public getFragment():?string
Checks if the fragment part of the URL is set
public containsFragment():bool
Create a new iterator to iterate through the URL components
public getIterator():Traversable
Determines whether the specified object is equal to the current object
public equals(URL|string $url):bool
Returns the object as a HTML5 encoded string
public __toString():string
Returns the object as a HTML5 encoded string
public parseToString(int $queryEncoding = 1):string
Checks whether the URL is current browser URL or not
public isCurrent():bool
Returns URL data as a scalar array
public toArray():array
Returns data which can be JSON serialized
public jsonSerialize():array
Returns the current URL as an object
public static getCurrentAsString(int $flags = 0):string
public static getRootAsString():string
Returns the current URL as an object
public static getCurrent():URL

Query string

A query string is a part of a uniform resource locator (URL) that assigns values to specified parameters. A query string commonly includes fields added to a base URL by a Web browser or other client application, for example as part of an HTML document, choosing the appearance of a page, or jumping to positions in multimedia content. [5]

QueryString parameter manipulation:

Parameters can also be manipulated using ArrayAccess interface

Synopsis
final public __construct(Traversable|object|array|string|null $query = null, ?string $separator = null)
Checks whether the query is empty
public isEmpty():bool
Sets the separator
public setSeparator(?string $separator):static
Checks whether a parameter exists in the query
public hasParameter(string|int $name):bool
Return the value of the parameter
public getParameter(string|int $name):mixed
Sets or replaces a parameter in the query
public setParameter(string|int $name, mixed $value):static
Removes a parameter from the query
public removeParameter(string|int $name):static
Sets or replaces parameters in the query
public merge(Traversable|object|array|string $params):static
Checks whether a parameter exists in the query
public offsetExists(mixed $name):bool
Return the value of the parameter
public offsetGet(mixed $name):mixed
Sets or replaces a parameter in the query
public offsetSet(mixed $name, mixed $value):void
Removes a parameter from the query
public offsetUnset(mixed $name):void
Returns the object as a HTML5 encoded string
public __toString():string
Returns the query string part of the URL
public build(int $encode = 1):string
public toRFC1738():string
public toRFC3986():string
Returns query parameters as an array
public jsonSerialize():array
Returns query parameters as an array
public toArray():array
Returns the current query string object
public static fromGET(int $filter = 516):QueryString
Parses and returns the query object from given url
public static fromURL(string $url):QueryString