PSR-7 URI implementation.

CloneableInstantiable
ImplementsPsr\Http\Message\UriInterface
Constants
public GuzzleHttp\Psr7\Uri::HTTP_DEFAULT_HOST = 'localhost'
 
Absolute http and https URIs require a host per RFC 7230 Section 2.7 but in generic URIs the host can be empty. So for http(s) URIs we apply this default host when no host is given yet to form a valid URI.

Methods
public __construct( $uri = '')
 


    public __toString()
    public static composeComponents( $scheme, $authority, $path, $query, $fragment)
     
    Composes a URI reference string from its various components.

    Usually this method does not need to be called manually but instead is used indirectly via
    Psr\Http\Message\UriInterface::__toString.

    PSR-7 UriInterface treats an empty component the same as a missing component as
    getQuery(), getFragment() etc. always return a string. This explains the slight
    difference to RFC 3986 Section 5.3.

    Another adjustment is that the authority separator is added even when the authority is missing/empty
    for the "file" scheme. This is because PHP stream functions like file_get_contents only work with
    file:///myfile but not with file:/myfile although they are equivalent according to RFC 3986. But
    file:/// is the more common syntax for the file scheme anyway (Chrome for example redirects to
    that format).

    public static fromParts(array $parts)
     
    Creates a URI from a hash of `parse_url` components.

    public getAuthority()
    public getFragment()
    public getHost()
    public getPath()
    public getPort()
    public getQuery()
    public getScheme()
    public getUserInfo()
    public static isAbsolute(Psr\Http\Message\UriInterface $uri)
     
    Whether the URI is absolute, i.e. it has a scheme.

    An instance of UriInterface can either be an absolute URI or a relative reference. This method returns true
    if it is the former. An absolute URI has a scheme. A relative reference is used to express a URI relative
    to another URI, the base URI. Relative references can be divided into several forms:

    • network-path references, e.g. '//example.com/path'
    • absolute-path references, e.g. '/path'
    • relative-path references, e.g. 'subpath'
    public static isAbsolutePathReference(Psr\Http\Message\UriInterface $uri)
     
    Whether the URI is a absolute-path reference.

    A relative reference that begins with a single slash character is termed an absolute-path reference.

    public static isDefaultPort(Psr\Http\Message\UriInterface $uri)
     
    Whether the URI has the default port of the current scheme.

    Psr\Http\Message\UriInterface::getPort may return null or the standard port. This method can be used
    independently of the implementation.

    • return bool
    public static isNetworkPathReference(Psr\Http\Message\UriInterface $uri)
     
    Whether the URI is a network-path reference.

    A relative reference that begins with two slash characters is termed an network-path reference.

    public static isRelativePathReference(Psr\Http\Message\UriInterface $uri)
     
    Whether the URI is a relative-path reference.

    A relative reference that does not begin with a slash character is termed a relative-path reference.

    public static isSameDocumentReference(Psr\Http\Message\UriInterface $uri, ?Psr\Http\Message\UriInterface $base = NULL)
     
    Whether the URI is a same-document reference.

    A same-document reference refers to a URI that is, aside from its fragment
    component, identical to the base URI. When no base URI is given, only an empty
    URI reference (apart from its fragment) is considered a same-document reference.

    public static removeDotSegments( $path)
     
    Removes dot segments from a path and returns the new path.

    • return string
    • deprecated since version 1.4. Use UriResolver::removeDotSegments instead.
    • see \UriResolver::removeDotSegments
    public static resolve(Psr\Http\Message\UriInterface $base, $rel)
     
    Converts the relative URI into a new URI that is resolved against the base URI.

    • return UriInterface
    • deprecated since version 1.4. Use UriResolver::resolve instead.
    • see \UriResolver::resolve
    public withFragment( $fragment)
    public withHost( $host)
    public static withoutQueryValue(Psr\Http\Message\UriInterface $uri, $key)
     
    Creates a new URI with a specific query string value removed.

    Any existing query string values that exactly match the provided key are
    removed.

    • return UriInterface
    public withPath( $path)
    public withPort( $port)
    public withQuery( $query)
    public static withQueryValue(Psr\Http\Message\UriInterface $uri, $key, $value)
     
    Creates a new URI with a specific query string value.

    Any existing query string values that exactly match the provided key are
    removed and replaced with the given key value pair.

    A value of null will set the query string key without a value, e.g. "key"
    instead of "key=value".

    • return UriInterface
    public static withQueryValues(Psr\Http\Message\UriInterface $uri, array $keyValueArray)
     
    Creates a new URI with multiple specific query string values.

    It has the same behavior as withQueryValue() but for an associative array of key => value.

    • return UriInterface
    public withScheme( $scheme)
    public withUserInfo( $user, $password = NULL)
    Properties
    private static $charSubDelims
    private static $charUnreserved
    private static $defaultPorts
    private $fragment
     


    • var string Uri fragment.
    private $host
     


    • var string Uri host.
    private $path
     


    • var string Uri path.
    private $port
     


    • var int|null Uri port.
    private $query
     


    • var string Uri query string.
    private static $replaceQuery
    private $scheme
     


    • var string Uri scheme.
    private $userInfo
     


    • var string Uri user info.
    Methods
    private applyParts(array $parts)
     
    Apply parse_url parts to a URI.

      private filterHost( $host)
       


      • return string
      • throws InvalidArgumentException If the host is invalid.
      private filterPath( $path)
       
      Filters the path of a URI

      • return string
      • throws InvalidArgumentException If the path is invalid.
      private filterPort( $port)
       


      • return int|null
      • throws InvalidArgumentException If the port is invalid.
      private filterQueryAndFragment( $str)
       
      Filters the query string or fragment of a URI.

      • return string
      • throws InvalidArgumentException If the query or fragment is invalid.
      private filterScheme( $scheme)
       


      • return string
      • throws InvalidArgumentException If the scheme is invalid.
      private filterUserInfoComponent( $component)
       


      • return string
      • throws InvalidArgumentException If the user info is invalid.
      private static generateQueryString( $key, $value)
       


      • return string
      private static getFilteredQueryString(Psr\Http\Message\UriInterface $uri, array $keys)
       


      • return array
      private rawurlencodeMatchZero(array $match)
      private removeDefaultPort()
      private validateState()
      Properties
      private static $charSubDelims
      private static $charUnreserved
      private static $defaultPorts
      private static $replaceQuery
      Methods
      public static composeComponents( $scheme, $authority, $path, $query, $fragment)
       
      Composes a URI reference string from its various components.

      Usually this method does not need to be called manually but instead is used indirectly via
      Psr\Http\Message\UriInterface::__toString.

      PSR-7 UriInterface treats an empty component the same as a missing component as
      getQuery(), getFragment() etc. always return a string. This explains the slight
      difference to RFC 3986 Section 5.3.

      Another adjustment is that the authority separator is added even when the authority is missing/empty
      for the "file" scheme. This is because PHP stream functions like file_get_contents only work with
      file:///myfile but not with file:/myfile although they are equivalent according to RFC 3986. But
      file:/// is the more common syntax for the file scheme anyway (Chrome for example redirects to
      that format).

      public static fromParts(array $parts)
       
      Creates a URI from a hash of `parse_url` components.

      private static generateQueryString( $key, $value)
       


      • return string
      private static getFilteredQueryString(Psr\Http\Message\UriInterface $uri, array $keys)
       


      • return array
      public static isAbsolute(Psr\Http\Message\UriInterface $uri)
       
      Whether the URI is absolute, i.e. it has a scheme.

      An instance of UriInterface can either be an absolute URI or a relative reference. This method returns true
      if it is the former. An absolute URI has a scheme. A relative reference is used to express a URI relative
      to another URI, the base URI. Relative references can be divided into several forms:

      • network-path references, e.g. '//example.com/path'
      • absolute-path references, e.g. '/path'
      • relative-path references, e.g. 'subpath'
      public static isAbsolutePathReference(Psr\Http\Message\UriInterface $uri)
       
      Whether the URI is a absolute-path reference.

      A relative reference that begins with a single slash character is termed an absolute-path reference.

      public static isDefaultPort(Psr\Http\Message\UriInterface $uri)
       
      Whether the URI has the default port of the current scheme.

      Psr\Http\Message\UriInterface::getPort may return null or the standard port. This method can be used
      independently of the implementation.

      • return bool
      public static isNetworkPathReference(Psr\Http\Message\UriInterface $uri)
       
      Whether the URI is a network-path reference.

      A relative reference that begins with two slash characters is termed an network-path reference.

      public static isRelativePathReference(Psr\Http\Message\UriInterface $uri)
       
      Whether the URI is a relative-path reference.

      A relative reference that does not begin with a slash character is termed a relative-path reference.

      public static isSameDocumentReference(Psr\Http\Message\UriInterface $uri, ?Psr\Http\Message\UriInterface $base = NULL)
       
      Whether the URI is a same-document reference.

      A same-document reference refers to a URI that is, aside from its fragment
      component, identical to the base URI. When no base URI is given, only an empty
      URI reference (apart from its fragment) is considered a same-document reference.

      public static removeDotSegments( $path)
       
      Removes dot segments from a path and returns the new path.

      • return string
      • deprecated since version 1.4. Use UriResolver::removeDotSegments instead.
      • see \UriResolver::removeDotSegments
      public static resolve(Psr\Http\Message\UriInterface $base, $rel)
       
      Converts the relative URI into a new URI that is resolved against the base URI.

      • return UriInterface
      • deprecated since version 1.4. Use UriResolver::resolve instead.
      • see \UriResolver::resolve
      public static withoutQueryValue(Psr\Http\Message\UriInterface $uri, $key)
       
      Creates a new URI with a specific query string value removed.

      Any existing query string values that exactly match the provided key are
      removed.

      • return UriInterface
      public static withQueryValue(Psr\Http\Message\UriInterface $uri, $key, $value)
       
      Creates a new URI with a specific query string value.

      Any existing query string values that exactly match the provided key are
      removed and replaced with the given key value pair.

      A value of null will set the query string key without a value, e.g. "key"
      instead of "key=value".

      • return UriInterface
      public static withQueryValues(Psr\Http\Message\UriInterface $uri, array $keyValueArray)
       
      Creates a new URI with multiple specific query string values.

      It has the same behavior as withQueryValue() but for an associative array of key => value.

      • return UriInterface
      © 2020 Bruce Wells
      Search Namespaces \ Classes
      ConfigurationNumbers (0-9.) only