Index

MMO\core\paths

MMO\core\paths ยท 24 symbols ยท generated 30 Sep 2026

function

absolute

paths.php:293

Make $path absolute, prefixing it with $root when it's relative (NOTE: the result is NOT simplified -- any ../. end up literally in the merged result; run it through simplify() yourself if you need that).

function absolute( array|string $path, array|string $root, bool $force = false, bool $join = true ): array|string|false
Namespace
MMO\core\paths
$patharray | stringan absolute or relative path
$rootarray | stringan absolute path
$force = falseboolif false (default) and $path is already absolute, $path is returned as-is and $root is ignored entirely; if true, $root is always applied -- an already absolute $path is rewritten as $root/relative($path, $root) instead
$join = trueboolif true, return a joined string; if false, return the segments array
returnsarray | string | falsefalse only possible when $force is true and $path can't be related to $root at all
absolute('marc', '/home/test'); // '/home/test/marc' absolute('/already/absolute', '/home/test'); // '/already/absolute' -- $root ignored, not forced absolute('../../test', '/home', true); // '/home/../../test' -- forced, not simplified absolute('/home', '/home/test', true); // '/home/test/..' -- forced: root always applies
Call graph
function

absoluteFilename

paths.php:538

Same as absolute(), but drive-aware (via isAbsoluteFilename()/relativeFilename() when $isWindows).

function absoluteFilename( array|string $path, array|string $root, bool $force = false, bool $join = true, bool $isWindows = MMO\core\paths\IS_WINDOWS ): array|string|false
Namespace
MMO\core\paths
$patharray | stringan absolute or relative path
$rootarray | stringan absolute path
$force = falseboolif true, $root always applies, even to an already-absolute $path (absolute())
$join = trueboolif true, return a joined string; if false, return the segments array
$isWindows = MMO\core\paths\IS_WINDOWSbool
returnsarray | string | false
absoluteFilename('c:/home/marc/test.php', 'c:/home/marc', true, true, true); // 'c:\home\marc\test.php'
Call graph
function

adrive

paths.php:380

Get the "drive" of an already-split path (segments array): / for a unix path (a leading empty segment), or the drive letter (e.g. c:) for a Windows one. The array-form counterpart of drive().

function adrive(array $path, bool $isWindows = MMO\core\paths\IS_WINDOWS): string|false
Namespace
MMO\core\paths
$patharraya split path (splitFilename())
$isWindows = MMO\core\paths\IS_WINDOWSbool
returnsstring | falsefalse if $path isn't absolute (has no drive/leading empty segment)
adrive(['', 'home', 'test'], false); // '/' adrive(['c:', 'home'], true); // 'c:'
Call graph
function

basename

paths.php:448

Extract the filename (last path segment) of a path -- almost the same as PHP's own \basename(), except that in $strict mode it returns false rather than the segment itself when that segment doesn't actually look like a "filename" (no extension, or a leading/trailing dot only -- e.g. a bare directory name, or a dotfile).

function basename(string $path, bool $removeExtension = false, bool $strict = false): string|false
Namespace
MMO\core\paths
$pathstring
$removeExtension = falseboolif true, the extension (and its '.') is stripped from the result
$strict = falseboolif true, return false instead of the last segment when it has no real extension
returnsstring | false
basename('/actually/this.is.a.filename'); // 'this.is.a.filename' basename('/actually/this.is.a.filename', true); // 'this.is.a' -- extension ('filename') stripped basename('linux/style.com', true); // 'style' basename('this_is_not a_filename', false, true); // false -- no '.' at all basename('.gitignore', false, true); // false -- leading dot only, not an extension
Call graph
function

dirname

paths.php:478

Extract the directory of a path (same as PHP's \dirname(), but normalizes \ to / first when $isWindows).

function dirname(string $path, bool $isWindows = MMO\core\paths\IS_WINDOWS): string
Namespace
MMO\core\paths
$pathstring
$isWindows = MMO\core\paths\IS_WINDOWSbool
returnsstring
dirname('c:\home\test', true); // 'c:/home'
Call graph
function

drive

paths.php:396

Get the "drive" of a path string: / for a unix path, or the drive letter (e.g. c:) for a Windows one.

function drive(string $path, bool $isWindows = MMO\core\paths\IS_WINDOWS): string|false
Namespace
MMO\core\paths
$pathstring
$isWindows = MMO\core\paths\IS_WINDOWSboolif false, a c:-style prefix is NOT recognized as a drive at all
returnsstring | falsefalse if $path isn't absolute
drive('/home/test'); // '/' drive('c:', true); // 'c:' drive('c:', false); // false -- windows drives not recognized drive('home/test', false); // false -- not absolute
Call graph
function

escape

paths.php:78

Escape ~ and / inside a single path segment, so it can safely be joined with / without being mistaken for a path separator (RFC 6902 JSON Pointer escaping: ~ -> ~0, / -> ~1).

function escape(string $item): string
Namespace
MMO\core\paths
$itemstringa single path segment (not a whole path)
returnsstring
escape('a/b~c'); // 'a~1b~0c'
Call graph
function

extension

paths.php:466

Extract the extension of a path (the part after the LAST '.' in its last segment), without the leading '.'.

function extension(string $path): ?string
Namespace
MMO\core\paths
A leading dot (e.g. '.gitignore') does not count as an extension.
$pathstring
returnsnull | stringthe extension without '.', or null if there isn't one
extension('/actually/this.is.a.filename'); // 'filename' extension('readme'); // null extension('.gitignore'); // null
Call graph
function

isAbsolute

paths.php:141

Tells if a path is absolute (starts with '/'; for the split/array form, has at least 2 segments and an empty leading one, per split()'s '/' => ['', ''] convention).

function isAbsolute(array|string $path): bool
Namespace
MMO\core\paths
$patharray | string
returnsbool
isAbsolute('/home/test'); // true isAbsolute('home/test'); // false isAbsolute(['', 'home']); // true
Call graph
function

isAbsoluteFilename

paths.php:427

Same as isAbsolute(), but for a real filename: also recognizes a Windows drive, and (for a string path) a URI authority (scheme://host/... or //host/...) as making the path absolute.

function isAbsoluteFilename(array|string $path, bool $isWindows = MMO\core\paths\IS_WINDOWS): bool
Namespace
MMO\core\paths
$patharray | string
$isWindows = MMO\core\paths\IS_WINDOWSboolif $path is a string that doesn't actually look like a Windows path (isWindowsFilename()), this is forced to false regardless of what's passed
returnsbool
isAbsoluteFilename('/home/test'); // true isAbsoluteFilename('c:\home', true); // true isAbsoluteFilename('home/test'); // false
Call graph
function

isWindowsFilename

paths.php:329

Heuristically tell if a path looks like a Windows path: either it uses \ and no / at all, or it starts with a valid drive letter immediately followed by a separator (or nothing else).

function isWindowsFilename(string $path): bool
Namespace
MMO\core\paths
$pathstringthe path to test
returnsbool
isWindowsFilename('c:\mes documents\marc\test.txt'); // true isWindowsFilename('foo\\bar'); // true (uses '\' only) isWindowsFilename('readme.txt'); // false isWindowsFilename('/home/marc/test.php'); // false
Call graph
function

join

paths.php:104

Join an array of path segments (as produced by split()) back into a path string, escaping each segment.

function join(array $path): string
Namespace
MMO\core\paths
$patharray
returnsstring
join([]); // '' join(['']); // './' -- the one special case: a single empty segment means "current dir with a trailing slash" join(['', '']); // '/' join(['a']); // 'a' join(['a', 'b']); // 'a/b' join(['', 'a', 'b']); // '/a/b' -- a leading empty segment means "absolute"
Call graph
function

joinFilename

paths.php:365

Same as join(), but converts every / to \ afterwards when $isWindows is true.

function joinFilename(array $path, bool $isWindows = MMO\core\paths\IS_WINDOWS): string
Namespace
MMO\core\paths
$patharray
$isWindows = MMO\core\paths\IS_WINDOWSbool
returnsstring
joinFilename(['c:', 'home', 'test'], true); // 'c:\home\test'
Call graph
function

matchMask

paths.php:31

Try to match a path against a mask made of plain segments, {name:type} moustache templates (matchTemplate), and wildcards: * matches exactly one segment, ** matches any number of trailing segments (and must be the mask's last segment).

function matchMask( array|string $mask, array|string $path, ?array &$matches = null, ?array $schemas = null ): int|true
Namespace
MMO\core\paths
$maskarray | stringthe mask to match against
$patharray | stringthe path to test
$matches = nullnull | array
$schemas = nullnull | arraythe schemas to use to coerce/validate a template's :type
returnsint | truetrue if $path matches. Else, the index of the first mask segment that failed to match.
matchMask('a', 'a/b', $m); // true, $m = [1 => 'b'] -- '*' matches exactly one segment matchMask('a*', 'a/b/c', $m); // true, $m = ['**' => 'b/c'] matchMask('a/b', 'a/x', $m); // 1 (segment 1, 'b', didn't match 'x')
Call graph
function

merge

paths.php:212

Concatenate several paths (segment arrays or path strings) into one, dropping the trailing empty segment of a path when the next one continues it (so joining doesn't produce a doubled /), and skipping empty inputs.

function merge(array|string ...$paths): array
Namespace
MMO\core\paths
...$pathsarray | string
returnsarraythe resulting segments (not joined into a string -- pass through join() for that)
merge('/a', 'b/c'); // ['', 'a', 'b', 'c'] merge('/a', 'b/c/', 'd/e', 'f'); // ['', 'a', 'b', 'c', 'd', 'e', 'f'] merge('/', './'); // ['', '.', '']
Call graph
function

normalizeFilename

paths.php:343

Replace every \ with /, turning a Windows-style path into a plain one split()/join() can handle.

function normalizeFilename(string $path): string
Namespace
MMO\core\paths
$pathstring
returnsstring
normalizeFilename('c:\home\test'); // 'c:/home/test'
Call graph
function

relative

paths.php:245

Express $path relative to $root (both simplified first, so ../. in either are resolved).

function relative( array|string $path, array|string $root, bool $strict = false, bool $join = true ): array|string|false
Namespace
MMO\core\paths
NOTE: a trailing slash on $root makes no difference to the result; one on $path is preserved on the result.
$patharray | stringan absolute path
$rootarray | stringan absolute path
$strict = falseboolif true, $path MUST be a descendant of $root (no leading .. allowed in the result) -- returns false instead if it isn't
$join = trueboolif true, return a joined string; if false, return the segments array
returnsarray | string | falsefalse if $path shares no common ancestor with $root (or, in strict mode, isn't a descendant)
relative('/home/test/marc', '/home/test'); // 'marc' relative('/home/..', '/home'); // '..' -- '/home/..' simplifies to '/' first relative('/home/marc', '/home/marc/test'); // '..' relative('/home/marc', '/home/marc/test', true); // false -- strict: the result would start with '..' relative('home/test', '/var'); // false -- no common ancestor (one relative, one absolute)
Call graph
function

relativeFilename

paths.php:517

Same as relative(), but drive-aware (via simplifyFilename() when $isWindows is true).

function relativeFilename( array|string $path, array|string $root, bool $strict = false, bool $join = true, bool $isWindows = MMO\core\paths\IS_WINDOWS ): array|string|false
Namespace
MMO\core\paths
$patharray | string
$rootarray | string
$strict = falseboolrelative()
$join = trueboolif true, return a joined string; if false, return the segments array
$isWindows = MMO\core\paths\IS_WINDOWSbool
returnsarray | string | false
relativeFilename('c:\home\marc', 'c:\home', false, true, true); // 'marc'
Call graph
function

simplify

paths.php:160

Simplify a path by resolving . and .. segments and dropping empty ones, without touching the filesystem (a leading .. past the root is dropped for an absolute path -- you can't go above / -- but is kept for a relative one, since there's nothing to resolve it against).

function simplify(array|string $path, bool $join = true): array|string
Namespace
MMO\core\paths
NOTE: the specific case of './' (current dir with a trailing slash) simplifies to `['']` in array form, not `[]`.
$patharray | string
$join = trueboolif true, return a joined string; if false, return the segments array
returnsarray | stringthe new path
simplify('a/b/c/..'); // 'a/b' simplify('/../../../test'); // '/test' -- can't go above root simplify('../../test'); // '../../test' -- kept as-is, relative simplify('/a/b/c/./../../g'); // '/a/g'
Call graph
function

simplifyFilename

paths.php:494

Same as simplify(), but drive-aware: a Windows drive is protected from being simplified away (c:\.. stays c:\, it never turns into just \, since going "above" the drive doesn't mean anything).

function simplifyFilename( array|string $path, bool $join = true, bool $isWindows = MMO\core\paths\IS_WINDOWS ): array|string
Namespace
MMO\core\paths
$patharray | string
$join = trueboolif true, return a joined string; if false, return the segments array
$isWindows = MMO\core\paths\IS_WINDOWSbool
returnsarray | string
simplifyFilename('c:\doc\..\test', true, true); // 'c:\test' simplifyFilename('c:\..', true, true); // 'c:\' -- the drive is never simplified away
Call graph
function

split

paths.php:125

Split a path string by / into segments, unescaping each one. The exact reverse of join().

function split(string $path): array
Namespace
MMO\core\paths
$pathstring
returnsarray
split(''); // [] split('/'); // ['', ''] -- a leading AND trailing empty segment means "root, with a trailing slash" split('.'); // ['.'] split('./'); // ['.', ''] split('a/'); // ['a', ''] split('a'); // ['a'] split('/key/~0param~0/~1get~1/test'); // ['', 'key', '~param~', '/get/', 'test']
Call graph
function

splitFilename

paths.php:354

Same as split(), but normalizes \ to / first when $isWindows is true.

function splitFilename(string $path, bool $isWindows = MMO\core\paths\IS_WINDOWS): array
Namespace
MMO\core\paths
$pathstring
$isWindows = MMO\core\paths\IS_WINDOWSbool
returnsarray
splitFilename('c:\home\test', true); // ['c:', 'home', 'test']
Call graph
function

unescape

paths.php:88

Reverse of escape().

function unescape(string $item): string
Namespace
MMO\core\paths
$itemstringan escaped single path segment
returnsstring
unescape('a~1b~0c'); // 'a/b~c'
function

validWindowsDrive

paths.php:411

Tells if a string is a syntactically valid Windows drive designation (a name made of characters allowed in a Windows filename, followed by :).

function validWindowsDrive(string $drive): bool
Namespace
MMO\core\paths
$drivestring
returnsbool
validWindowsDrive('c:'); // true validWindowsDrive('my_drive:'); // true validWindowsDrive('my*drive:'); // false -- '*' is not allowed in a Windows filename
Call graph

Used by (2)