Index

Uri

MMO\core\helpers ยท 1 symbol ยท generated 30 Sep 2026

class

Uri

Uri.php:20

A Path extended with scheme/host/user/password/port/query/fragment -- a full PSR-7 UriInterface, plus the same ArrayAccess/basepath machinery as Path (accessed via string keys: 'scheme', 'host', 'user', 'password', 'port', 'query', 'fragment', 'path' -- alongside Path's own numeric segment indices).

class MMO\core\helpers\Uri extends MMO\core\helpers\Path implements Psr\Http\Message\UriInterface
Namespace
MMO\core\helpers
Extends
Path
Implements
UriInterface
$uri = new Uri('https://user:secret@example.com:8080/base/path?a=1#frag', 2); $uri->getHost(); // 'example.com' $uri->getAuthority(); // 'user:secret@example.com:8080' $uri['query']; // ['a' => '1']

Index

ALLa mask for url's flag
AUTHORITY
FRAGMENTinclude url any fragments (#identifier)
HOSTinclude url host information
ORIGIN
PASSWORDinclude url any password authentication information
PORTinclude url explicit port numbers
QUERYinclude url query string
REL_FILENAME_POSget only the relative file's path and position
REL_URL
ROOTget the root part of the url
SCHEMEinclude url scheme
SERVERget the server part of the url
URL_SPECIFICthe url specifics parts
USERinclude url any user authentication information
fragment
host
LOCAL_HOSTS static
LOCAL_SCHEMES static
password
port
query
scheme
user
clear()
cloneForWith()A mutable clone of $this to apply one change to, later restored (restoreImmutability) to $this's own immutability state -- used by every with*() method below.
debugName()
exists()
flags()Get set parts of the filename
FlagsText($flags, $sep) staticConvert binary url flags to list of strings
getAuthority()
getFragment()
getHost()
getOrigin()
getParsedQuery()
getPassword()
getPath()
getPathAsArray()
getPort()
getQuery()
getRelative($simplify)
getRoot()
getScheme()
getUser()
getUserInfo()
Immutable($path, $root, $isWindows) staticSame as the constructor, but the returned Uri is Path::isImmutable.
isAbsolute()
isLocal()
isLoopback($ignoreScheme)According to section 7.3 of rfc8252, loopback uris are: - "http://127.0.0.1:{port}/{path}" for IPv4 - "http://[::1]:{port}/{path}" for IPv6
offsetExists($key)\ArrayAccess::offsetExists
offsetGet($key)\ArrayAccess::offsetGet
offsetSet($key, $value)\ArrayAccess::offsetSet
offsetUnset($key)\ArrayAccess::offsetUnset
rebase($uri)Re-root this URI onto $uri.
render($opts)Render the filename
restoreImmutability($clone)Restore $clone to $this's own immutability state, once a with*() method is done mutating it.
Server() static
set($uri)Set the whole URI, replacing every component.
setFragment($value)
setHost($value)
setPassword($value)
setPath($path)
setPort($value)
setQuery($value)
setScheme($value)
setUser($value)
toArray()
withFragment($fragment)
withHost($host)
withPath($path)
withPort($port)
withQuery($query)
withScheme($scheme)
withUserInfo($user, $password)
__construct($path, $root, $isWindows)

Constants15

ALL

a mask for url's flag

const ALL = 2047

AUTHORITY

const AUTHORITY = 30

FRAGMENT

include url any fragments (#identifier)

const FRAGMENT = 1024

HOST

include url host information

const HOST = 2

ORIGIN

const ORIGIN = 992

PASSWORD

include url any password authentication information

const PASSWORD = 8

PORT

include url explicit port numbers

const PORT = 16

QUERY

include url query string

const QUERY = 512

REL_FILENAME_POS

get only the relative file's path and position

const REL_FILENAME_POS = 1472

REL_URL

const REL_URL = 1984

ROOT

get the root part of the url

const ROOT = 63

SCHEME

include url scheme

const SCHEME = 1

SERVER

get the server part of the url

const SERVER = 31

URL_SPECIFIC

the url specifics parts

const URL_SPECIFIC = 1567

USER

include url any user authentication information

const USER = 4

Properties9

fragment

protected ?string $fragment
Type
null | string

LOCAL_HOSTS

static
static $LOCAL_HOSTS = ['localhost', '[::1]']

LOCAL_SCHEMES

static
static $LOCAL_SCHEMES = ['file', 'phar']

password

protected ?string $password
Type
null | string

port

protected ?int $port
Type
null | int

query

protected array $query
Type
array

Methods51

clear()

Uri.php:268
function clear(): void
returnsvoidreset every component to empty/null, same as set('')

cloneForWith()

Uri.php:514

A mutable clone of $this to apply one change to, later restored (restoreImmutability) to $this's own immutability state -- used by every with*() method below.

protected function cloneForWith(): selfNOTE: a plain `clone $this` does NOT reset the [`Path::isImmutable`](https://mmoframework.fr/documentation/mmo.core/php/helpers/Path.md#path-isimmutable) flag (unlike [`Path::toMutable`](https://mmoframework.fr/documentation/mmo.core/php/helpers/Path.md#path-tomutable) /
See
Path::toImmutable, which always explicitly set it after cloning), so mutating the clone used to immediately throw "immutable. cannot be changed." for ANY Uri that started out immutable -- which is the normal case (e.g. every Request's own URI is always immutable, see aRequest::setUri()).
returnsself

debugName()

Uri.php:132
function debugName(): string
returnsstringe.g. '(uri)https://example.com/path'

exists()

Uri.php:149
function exists(): bool
returnsbooltrue if the local file/path this URI points at actually exists

flags()

Uri.php:168

Get set parts of the filename

function flags(): int
returnsint$flags binary combination of self::* constant

FlagsText($flags, $sep)

staticUri.php:186

Convert binary url flags to list of strings

static function FlagsText($flags, $sep = ','): array|string
$flagsthe flags to test
$sep = ','the separator to use to concat the values, or false to return as array
returnsarray | string

getAuthority()

Uri.php:435
function getAuthority(): string
returnsstringPSR-7's "[user-info@]host[:port]" format NOTE: this used to delegate to \MMO\core\uris\join(), which is built for rendering a FULL uri string -- given a 'scheme' key it prepends "scheme:", and given a 'host' key it unconditionally prepends "//" first (both wrong for a bare authority). It also reads the password under the key 'pass', not 'password' (the key this method used to pass), which silently dropped it too. Net effect: this was a real, demonstrated bug -- since aRequest::setUri() sets the Host header from getAuthority(), every Request ended up with a Host header like "https://user:secret@example.com:8080" instead of "example.com:8080".

getHost()

Uri.php:477
function getHost(): string
returnsstringlowercase host, or '' if none (per PSR-7)

getOrigin()

Uri.php:442
function getOrigin(): string
returnsstringPSR-7 origin-form: path + query, no scheme/authority/fragment

getParsedQuery()

Uri.php:496
function getParsedQuery(): array
returnsarraythe query already parsed into key => value

getPath()

Uri.php:410
function getPath(): string
returnsstringthe full path (no scheme/host/query/fragment)

getPort()

Uri.php:486
function getPort(): ?int
returnsnull | intNOTE: was declared int (non-nullable), unlike PSR-7's own UriInterface::getPort(): ?int -- a URI with no explicit port (the common case) always crashed with "Return value must be of type int, null returned".

getQuery()

Uri.php:491
function getQuery(): string
returnsstringthe raw query string (no leading '?'), per PSR-7

getRelative($simplify)

Uri.php:401
function getRelative(bool $simplify = true): string
$simplify = trueboolif true, resolve '.'/'..' in the relative path first
returnsstringthe relative path (past the basepath) + query + fragment -- no scheme/host
(new Uri('https://example.com/base/rel', 2))->getRelative(); // 'rel'

getRoot()

Uri.php:450
function getRoot(): string
returnsstringthe server root: scheme + authority + basepath (no relative path, query or fragment) NOTE: see getAuthority -- same 'pass' vs 'password' key fix applies here.

getScheme()

Uri.php:422
function getScheme(): string
returnsstringe.g. 'https', or '' if none

getUserInfo()

Uri.php:471
function getUserInfo(): string
returnsstringPSR-7's own "username[:password]" format -- no scheme/host/'@', unlike the rest of the URI NOTE: this used to delegate to \MMO\core\uris\join(), which only ever renders user/password when a 'host' key is ALSO present (it's meant for building a full URI, not extracting just the userinfo substring) -- so that call could never produce any output at all, on top of also referencing the undeclared $this->pass (the real property is $password).

Immutable($path, $root, $isWindows)

staticUri.php:84

Same as the constructor, but the returned Uri is Path::isImmutable.

static function Immutable( array|string $path = '', string|int|null $root = null, bool $isWindows = false )
$path = ''array | string
$root = nullstring | int | null
$isWindows = falsebool
returns

isAbsolute()

Uri.php:139
function isAbsolute(): bool
returnsbooltrue for any non-isLocal URI (which are absolute by having a real host), or a local one whose path is absolute

isLoopback($ignoreScheme)

Uri.php:160
According to section 7.3 of rfc8252, loopback uris are: - "http://127.0.0.1:{port}/{path}" for IPv4 - "http://[::1]:{port}/{path}" for IPv6function isLoopback(bool $ignoreScheme = false): bool
$ignoreScheme = falsebool
returnsbool

offsetExists($key)

Uri.php:660

\ArrayAccess::offsetExists

function offsetExists(mixed $key): bool
$keymixed
returnsbool

offsetGet($key)

Uri.php:604

\ArrayAccess::offsetGet

function offsetGet(mixed $key): mixed
$keymixed
returnsmixed

offsetSet($key, $value)

Uri.php:638

\ArrayAccess::offsetSet

function offsetSet(mixed $key, mixed $value): void
$keymixed
$valuemixed
returnsvoid

offsetUnset($key)

Uri.php:581

\ArrayAccess::offsetUnset

function offsetUnset(mixed $key): void
$keymixed
returnsvoid

rebase($uri)

Uri.php:358

Re-root this URI onto $uri. If $uri has an authority (scheme/host/...), every URI component is replaced by $uri's; otherwise (a plain path), only the path's basepath is affected (same as Path::rebase).

function rebase(MMO\core\helpers\Path|array|string|bool $uri): void
$uriPath | array | string | bool
returnsvoid
throwsif isImmutable
(new Uri('/a/b/c'))->rebase('https://example.com'); // 'https://example.com/a/b/c'

render($opts)

Uri.php:117

Render the filename

function render(array $opts = []): string
$opts = []array- scheme: if false, remove the scheme. - host: if false, remove the host. - user: if false, remove the user. - pass: if false, remove the pass. - port: if false, remove the port. - path: if false, remove the path. - query: if false, remove the query. - fragment: if false, remove the fragment. - basepath: if false, remove the basepath. if string, render the relative path compare to basepath
returnsstring

restoreImmutability($clone)

Uri.php:523

Restore $clone to $this's own immutability state, once a with*() method is done mutating it.

protected function restoreImmutability(self $clone): self
$cloneself
returnsself$clone

Server()

staticUri.php:203
static function Server(): self
returnsselfthe current request's own URI (basepath rebased to the application's own root URL)

toArray()

Uri.php:89
function toArray(): array
returnsarrayscheme/host/user/pass/port/path/query/fragment

withScheme($scheme)

Uri.php:532
function withScheme(string $scheme): self
$schemestring
returnsself
$uri2 = $uri->withScheme('http'); // used to always throw if $uri was immutable

withUserInfo($user, $password)

Uri.php:539
function withUserInfo($user, $password = null): self
See
withScheme's note about immutability
$user
$password = null
returnsself

__construct($path, $root, $isWindows)

Uri.php:76
function __construct( array|string $path = '', string|int|null $root = null, bool $isWindows = false )
$path = ''array | stringa full/partial URI string, or an already-split array (scheme/host/user/pass/port/path/query/fragment)
$root = nullstring | int | nullthe basepath's end index, or a root path to rebase against (see Path::__construct)
$isWindows = falsebool
Inherited members (44)
ConstantsDeclared byDescription
ABS_FILENAMEPathget absolute filename
BASENAMEPathget only the file's name and extension
BASE_PATHPathinclude url base path
EXTENSIONPathinclude url extension
FILEPathinclude url file
PATHPathget only the file's path
REL_FILENAMEPathget only the relative filename
REL_PATHPathinclude url relative path
STATUS_WINDOWSPath
PropertiesDeclared byDescription
basePath
contentPath
immutablePath
windowsPath
MethodsDeclared byDescription
addPath($path)PathAppend $path (via merge, which resolves any '..'/'.' against the existing content).
count()Path\Countable::count
empty()Path
getBaseIndex()Path
getBasename()PathGet the filename on the path
getBasepath($join)PathGet the basepath. If non empty, it is always returned with en ending '/'
getExtension()Path
getFile()Path
getIterator()Path\IteratorAggregate::getIterator
getRelpath($join)PathGet the relative part of the path
getSimplified($join)Path
hasBasename()PathTells if path has a filename at the end of its path
hasBasepath()Path
hasRelpath($strict)Path
isImmutable()Path
isWindows()Path
jsonSerialize()Path
relativeTo($root, $strict)PathMake path relative to a root
removePath($number)PathRemove the last $number segments.
setBaseIndex($index)PathSet the base index (used internally)
setBasename($file)PathReplace the last segment (the filename, if any) with $file.
setBasepath($path)PathSet the basepath, keeping the existing relative path.
setExtension($ext)PathReplace the filename's extension, keeping its name.
setFile($file)PathReplace the filename's name, keeping its extension.
setRelpath($path)PathSet the relative part of the path, keeping the existing basepath.
setWindows($value)Path
simplify()PathSimplifies path, removing `, .. and .` WARNING: change the basepath index if the simplified path reduced it
slice($offset, $length, $join)Path
toImmutable($forceClone)Path
toMutable($forceClone)Path
__toString()Path