canonicalizePath.php
Table of Contents
Functions
- canonicalizePath() : string
- Converts any given path to a **canonical, absolute‑style** representation.
Functions
canonicalizePath()
Converts any given path to a **canonical, absolute‑style** representation.
canonicalizePath(string $path) : string
The algorithm:
- Early return / cache – looks up the path in a static LRU‑style buffer (see CanonicalizeBuffer).
- Home expansion – replaces a leading tilde
~
with the current user’s home directory (platform‑aware via getHomeDirectory()). - Separator normalisation – back‑slashes ⇒ forward‑slashes via normalizePath().
- Root / remainder split – handled by splitPath().
- Dot & dot‑dot cleanup – collapses
.
and..
segments with extractCanonicalParts(). - Buffer write‑back – stores the result; periodically cleans the buffer after insertions.
No filesystem access is performed; non‑existent paths are allowed.
Parameters
- $path : string
-
The path to canonicalise. May be relative or absolute, Windows or Unix, and may start with
~
.
Tags
Return values
string —Canonicalised path with forward slashes and no redundant
.
/ ..
segments.