Index

MMO\core\uris

MMO\core\uris · 16 symbols · generated 30 Sep 2026

function

absolute

uris.php:397

Fill in whatever $uri is missing (scheme, host/user/pass/port, path) from $root.

function absolute( array|string $uri, array|string $root, bool $strict = true, bool $join = true ): array|string
Namespace
MMO\core\uris
NOTE: this is a simple "inherit what's missing" rebase, NOT RFC 3986 reference resolution -- use [`resolve()`](https://mmoframework.fr/documentation/mmo.core/php/uris.md#resolve) for that (it correctly handles `.`/`..` relative to the current document, per the RFC).
$uriarray | string
$rootarray | stringthe root uri to fill in from
$strict = trueboolif false, $uri's own scheme (if any) is kept even when it differs from $root's; if true (default), $root is only applied when the schemes match (or $uri has none)
$join = trueboolif true, return a joined string; if false, return the parts array
returnsarray | string
absolute('/a/b', 'http://host', true, true); // 'http://host/a/b'
Call graph
function

apiQuery

uris.php:312

Build a query string in the {json:api} convention (filters[...], sort=, fields=, page[limit]/page[offset]).

function apiQuery( array|string|null $filters = null, array|string|null $fields = null, array|string|null $sort = null, ?int $limit = null, ?int $offset = null, ?array $search = null ): string
Namespace
MMO\core\uris
NOTE: $fields and $sort, when given as an array, MUST be associative (`['name' => bool]`, true = include, e.g. ascending for sort/present for fields) -- a plain list entry (no explicit key) is not a valid shape here.
$filters = nullarray | string | nulla raw filters string, or ['field' => value, ...]
$fields = nullarray | string | nulla raw fields string, or ['field' => bool, ...] (false prefixes with -)
$sort = nullarray | string | nulla raw sort string, or ['field' => bool, ...] (false -> descending, prefixed with -)
$limit = nullnull | int
$offset = nullnull | int
$search = nullnull | array
returnsstringa query string, NOT prefixed with '?'
apiQuery(['status' => 'active'], ['name' => true, 'id' => false], ['name' => true], 10, 0); // 'filters[status]=active&sort=name&fields=name,-id&page[limit]=10&page[offset]=0' (before urlencoding)
Call graph
function

buildQuery

uris.php:242

Same as \http_build_query(), except it can round-trip true (encoded as a bare key, no =value) and null (encoded as key=NULL) -- \http_build_query() alone can't distinguish those from '1'/''.

function buildQuery(array $data): string
Namespace
MMO\core\uris
The exact reverse of [`splitQuery()`](https://mmoframework.fr/documentation/mmo.core/php/uris.md#splitquery).
$dataarray
returnsstringa query string, NOT prefixed with '?'
buildQuery(['a' => null, 'b' => true, 'c' => 'x']); // 'b&c=x&a=NULL'
Call graph
function

extension

uris.php:95

Extract the extension from a uri's path (query/fragment are stripped first, so they don't interfere).

function extension(string $uri): ?string
Namespace
MMO\core\uris
$uristring
returnsnull | stringthe extension without ., or null if there isn't one
extension('https://host/a/b.php?q=1#f'); // 'php'
Call graph
function

hasAuthority

uris.php:50

Tells if a uri has a scheme:// authority part at all (of any scheme).

function hasAuthority(string $uri)
Namespace
MMO\core\uris
$uristring
returns
hasAuthority('https://host/a'); // true
Call graph
function

hasLocalAuthority

uris.php:64

Tells if a uri's scheme is one of this framework's "local" schemes (Uri::$LOCAL_SCHEMES, e.g. 'file'/'phar') -- these are treated specially throughout this file (their authority is not a real network host, so it's folded back into the path instead -- path()/split()).

function hasLocalAuthority(string $uri)
Namespace
MMO\core\uris
$uristring
returns
hasLocalAuthority('file://test.php'); // true hasLocalAuthority('https://host/a'); // false
Call graph
function

isAbsolute

uris.php:81

Tells if a uri is absolute: it has a network authority (scheme://host/..., or -- in $strict mode -- a local-scheme authority followed by /), or (falling back to isAbsoluteFilename()) it looks like an absolute filesystem path.

function isAbsolute(string $uri, bool $strict = true)
Namespace
MMO\core\uris
$uristring
$strict = trueboolif false, any scheme://... (local scheme or not) counts as absolute regardless of what follows the authority
returns
isAbsolute('https://host/a'); // true isAbsolute('/a/b'); // true isAbsolute('a/b'); // false
Call graph
function

join

uris.php:206

Reverse of split(): join a parts array back into a uri string.

function join(array $uri): string
Namespace
MMO\core\uris
$uriarraya subset of: scheme, user, pass, host, port, path, query, fragment
returnsstring
join(['scheme' => 'https', 'host' => 'host', 'path' => '/a/b', 'query' => ['p' => '1']]); // 'https://host/a/b?p=1'
Call graph
function

matchMask

uris.php:359

Try to match an uri against a mask.

function matchMask( array|string $mask, array|string $uri, ?array &$matches = null, ?array $schemas = null ): string|true
Namespace
MMO\core\uris
The mask can contain template with moustache (@example `{drive:string}/test`) or schemas. For the path, wildcards `*` are replaced by one item, `**` works for any number of ending items.
$maskarray | stringa split (or splittable) uri whose 'path'/'query' are matched with the dedicated path/query matchers (matchMask()/matchMask()), and any other part (scheme, host, port, user, pass, fragment) is matched generically
$uriarray | stringa split (or splittable) uri to test
$matches = nullnull | array
$schemas = nullnull | arraya list of schemas to use for the type in placeholders. if null, use the global schemas
returnsstring | truetrue if it matches or the mask item key on which the uri has failed to match.
matchMask(['path' => 'a/{x}'], ['path' => 'a/b'], $matches); // true, $matches = ['x' => 'b'] matchMask(['scheme' => 'https'], ['scheme' => 'http']); // 'scheme' -- the mismatching key
Call graph
function

path

uris.php:21

Extract just the path component of a uri (stripping scheme/authority/query/fragment). A cheaper shortcut for split($uri)['path'] when you don't need the rest of the uri parsed.

function path(string $uri, ?bool $isWindows = null): string
Namespace
MMO\core\uris
$uristring
$isWindows = nullnull | boolif null, auto-detected: a non-authority uri that looks like a Windows filename (isWindowsFilename()) is normalized (\ -> /)
returnsstring
path('https://host/a/b?q=1#f'); // '/a/b' path('file:///test.php'); // '/test.php'
Call graph
function

relative

uris.php:452

The reverse of absolute(): strip out from $uri whatever it shares with $root (scheme, host/user/pass, matching port, and the common leading part of the path -- relative()), so re-applying absolute($result, $root) recovers $uri.

function relative($uri, $root, bool $strict = false, bool $join = true)
Namespace
MMO\core\uris
NOTE: this is NOT the same as [`unresolve()`](https://mmoframework.fr/documentation/mmo.core/php/uris.md#unresolve): here the WHOLE of $root's path is used as the base (not just the part before its last '/', as unresolve()/RFC 3986 reference resolution does).
$uri
$root
$strict = falseboolpassed to \MMO\core\paths\relative(): if true, $uri's path must be a descendant of $root's (no leading .. allowed in the result)
$join = trueboolif true, return a joined string; if false, return the parts array
returnsfalse if $uri and $root have different hosts (they share no common base at all)
relative('http://host/test.php', 'http://host/a/b'); // '../../test.php' relative('https://host/a/b', 'http://host/a/b'); // 'https:' -- differing scheme is kept, prefixed
Call graph
function

resolve

uris.php:511

Resolve $uri against a base uri and simplify the resulting path -- a direct implementation of RFC 3986's reference resolution algorithm (unlike absolute(), this correctly treats $base's path as a DOCUMENT, dropping everything after its last '/' before applying $uri, exactly like a browser resolving a relative link).

function resolve($uri, $base, bool $strict = true, bool $join = true)
Namespace
MMO\core\uris
WARNING: a base path MUST end with `/` to be used entirely as a directory. base `/home/marc` and relative uri `lima`, gives `/home/lima` base `/home/marc/` and relative uri `lima`, gives `/home/marc/lima` base `/home/marc/index.php` and relative `page.php`, gives `/home/marc/page.php`
$uri
$basethe base uri to resolve against
$strict = trueboolpassed to absolute(): if false, allow $uri's own scheme to be kept even when it's relative to $base with a different scheme
$join = trueboolif true, return a joined string; if false, return the parts array
returns
resolve('../g', 'http://a/b/c/d;p?q=1'); // 'http://a/b/g' resolve('g?y=1#s', 'http://a/b/c/d;p?q=1'); // 'http://a/b/c/g?y=1#s' resolve('//g', 'http://a/b/c/d;p?q=1'); // 'http://g' -- a network-path reference replaces the whole authority
Call graph
function

simplify

uris.php:110

Simplify a uri's path component in place (resolving ./.. -- simplify()), leaving the rest of the uri untouched.

function simplify(string $uri, bool $join = true)
Namespace
MMO\core\uris
$uristring
$join = trueboolif true, return a joined string; if false, return the split parts array
returns
simplify('/a/b/../c'); // '/a/c'
Call graph
function

split

uris.php:133

Parse a uri into its RFC 3986 parts. Only the parts actually present in $uri are set (e.g. a path-only uri yields just ['path' => ...]); the query string is itself parsed into an array (splitQuery()).

function split(string $uri, bool $isWindows = MMO\core\uris\IS_WINDOWS): array
Namespace
MMO\core\uris
$uristring
$isWindows = MMO\core\uris\IS_WINDOWSboolif true, the path part is normalized (\ -> /)
returnsarraya subset of: scheme, user, pass, host, port, path, query, fragment
split('https://marc:pwd@host:8080/a/b?p=1#f'); // ['scheme'=>'https', 'user'=>'marc', 'pass'=>'pwd', 'host'=>'host', 'port'=>8080, 'path'=>'/a/b', 'query'=>['p'=>'1'], 'fragment'=>'f'] split('file:///test.php'); // ['scheme' => 'file', 'path' => '/test.php'] -- a local scheme has no real host split('test.php'); // ['path' => 'test.php']
Call graph
function

splitQuery

uris.php:275
Same as \parse_str(), except it distinguishes the three ways an "empty" query value can be written -- the exact reverse of [`buildQuery()`](https://mmoframework.fr/documentation/mmo.core/php/uris.md#buildquery): - `xxx=` -> `''` (empty string) - `xxx` (no `=` at all) -> `true` - `xxx=NULL` -> `null`function splitQuery(string $query): array
Namespace
MMO\core\uris
$querystringa query string, without the leading '?'
returnsarray
splitQuery('a=NULL&b&c=x'); // ['a' => null, 'b' => true, 'c' => 'x']
Call graph
function

unresolve

uris.php:536

The reverse of resolve(): recover the relative uri that, resolved against $base, would produce $uri.

function unresolve($uri, $base, bool $strict = false, bool $join = true)
Namespace
MMO\core\uris
NOTE: make sure $base is exactly the same (with or without a trailing slash) as the one used in resolve().
$uri
$base
$strict = falseboolif true, don't allow the result's path to start with .. (i.e. $uri's path must be a descendant of $base's directory); if false (default), .. is allowed
$join = trueboolif true, return a joined string; if false, return the parts array
returnsfalse in strict mode if $uri can't be expressed without a leading ..
unresolve('http://a/b/g', 'http://a/b/c/d;p?q=1'); // '../g' unresolve('http://a/b/c/g?y=1#s', 'http://a/b/c/d;p?q=1'); // 'g?y=1#s'
Call graph