if (isset(self::
$buffer[$path])) { return self::
$buffer[$path];
} // Replace "~" with user's home directory.
if ('~' ===
$path[0
]) { $path = self::
getHomeDirectory().
substr($path, 1
);
} $path = self::
normalize($path);
[$root,
$pathWithoutRoot] = self::
split($path);
$canonicalParts = self::
findCanonicalParts($root,
$pathWithoutRoot);
// Add the root directory again
self::
$buffer[$path] =
$canonicalPath =
$root.
implode('/',
$canonicalParts);
++self::
$bufferSize;
// Clean up regularly to prevent memory leaks
if (self::
$bufferSize > self::CLEANUP_THRESHOLD
) { self::
$buffer = \
array_slice(self::
$buffer, -self::CLEANUP_SIZE, null, true
);
self::
$bufferSize = self::CLEANUP_SIZE;
}