PHP Class GuzzleHttp\Psr7\UriNormalizer

Author: Tobias Schultze
Show file Open project: nystudio107/instantanalytics Class Usage Examples

Public Methods

Method Description
isEquivalent ( Psr\Http\Message\UriInterface $uri1, Psr\Http\Message\UriInterface $uri2, integer $normalizations = self::PRESERVING_NORMALIZATIONS ) : boolean Whether two URIs can be considered equivalent.
normalize ( Psr\Http\Message\UriInterface $uri, integer $flags = self::PRESERVING_NORMALIZATIONS ) : Psr\Http\Message\UriInterface Returns a normalized URI.

Private Methods

Method Description
__construct ( )
capitalizePercentEncoding ( Psr\Http\Message\UriInterface $uri )
decodeUnreservedCharacters ( Psr\Http\Message\UriInterface $uri )

Method Details

isEquivalent() public static method

Both URIs are normalized automatically before comparison with the given $normalizations bitmask. The method also accepts relative URI references and returns true when they are equivalent. This of course assumes they will be resolved against the same base URI. If this is not the case, determination of equivalence or difference of relative references does not mean anything.
public static isEquivalent ( Psr\Http\Message\UriInterface $uri1, Psr\Http\Message\UriInterface $uri2, integer $normalizations = self::PRESERVING_NORMALIZATIONS ) : boolean
$uri1 Psr\Http\Message\UriInterface An URI to compare
$uri2 Psr\Http\Message\UriInterface An URI to compare
$normalizations integer A bitmask of normalizations to apply, see constants
return boolean

normalize() public static method

The scheme and host component are already normalized to lowercase per PSR-7 UriInterface. This methods adds additional normalizations that can be configured with the $flags parameter. PSR-7 UriInterface cannot distinguish between an empty component and a missing component as getQuery(), getFragment() etc. always return a string. This means the URIs "/?#" and "/" are treated equivalent which is not necessarily true according to RFC 3986. But that difference is highly uncommon in reality. So this potential normalization is implied in PSR-7 as well.
public static normalize ( Psr\Http\Message\UriInterface $uri, integer $flags = self::PRESERVING_NORMALIZATIONS ) : Psr\Http\Message\UriInterface
$uri Psr\Http\Message\UriInterface The URI to normalize
$flags integer A bitmask of normalizations to apply, see constants
return Psr\Http\Message\UriInterface The normalized URI