URI information
The League\Uri\UriInfo
contains a list of public static methods which returns a list of information regarding the URI object submitted.
UriInfo::isAbsolute
This public static method tells whether the given URI object represents an absolute URI.
<?php
use League\Uri\Http;
use League\Uri\Uri;
use League\Uri\UriInfo;
UriInfo::isAbsolute(Uri::createFromServer($_SERVER)); //returns true
UriInfo::isAbsolute(Http::createFromString("/π£πΊ")); //returns false
UriInfo::isAbsolutePath
This public static method tells whether the given URI object represents an absolute URI path.
UriInfo::isAbsolutePath(Uri::createFromServer($_SERVER)); //returns false
UriInfo::isAbsolutePath(Http::createFromString("/π£πΊ")); //returns true
UriInfo::isNetworkPath
This public static method tells whether the given URI object represents an network path URI.
UriInfo::isNetworkPath(Http::createFromString("//example.com/toto")); //returns true
UriInfo::isNetworkPath(Uri::createFromString("/π£πΊ")); //returns false
UriInfo::isRelativePath
This public static method tells whether the given URI object represents a relative path.
UriInfo::isRelativePath(Http::createFromString("π³οΈβπ")); //returns true
UriInfo::isRelativePath(Http::createFromString("/π£πΊ")); //returns false
UriInfo::isSameDocument
This public static method tells whether the given URI object represents the same document.
UriInfo::isSameDocument(
Http::createFromString("example.com?foo=bar#π³οΈβπ"),
Http::createFromString("exAMpLE.com?foo=bar#π£πΊ")
); //returns true
UriInfo::getOrigin
This public static method returns the URI origin as defined by the WHATWG URL Living standard
<?php
use League\Uri\Http;
use League\Uri\Uri;
use League\Uri\UriInfo;
UriInfo::getOrigin(Http::createFromString('https://uri.thephpleague.com/uri/6.0/info/')); //returns 'https://uri.thephpleague.com'
UriInfo::getOrigin(Uri::createFromString('blob:https://mozilla.org:443')); //returns 'https://mozilla.org'
UriInfo::getOrigin(Http::createFromString('file:///usr/bin/php')); //returns null
UriInfo::getOrigin(Uri::createFromString('data:text/plain,Bonjour%20le%20monde%21')); //returns null
Because the origin property does not exists in the RFC3986 specification this additional steps is implemented:
- For non absolute URI the method will return
null
<?php
use League\Uri\Http;
use League\Uri\UriInfo;
UriInfo::getOrigin(Http::createFromString('/path/to/endpoint')); //returns null
UriInfo::isCrossOrigin
This public static method tells whether the given URI object represents different origins. According to RFC9110 The βoriginβ for a given URI is the triple of scheme, host, and port after normalizing the scheme and host to lowercase and normalizing the port to remove any leading zeros.
<?php
use GuzzleHttp\Psr7\Utils;
use League\Uri\Http;
use League\Uri\Uri;
use League\Uri\UriInfo;
use Nyholm\Psr7\Uri;
UriInfo::isCrossOrigin(
Utils::uriFor('blob:http://xn--bb-bjab.be./path'),
new Uri('http://BΓ©bΓ©.BE./path'),
); // returns false
UriInfo::isCrossOrigin(
Http::createFromString('https://example.com/123'),
Uri::createFromString('https://www.example.com/')
); // returns true
The method expects URI objects (implementing the League or PSR-7 UriInterface
).
The method takes into account i18n while comparing both URI id the intl-extension
is installed.