function Path::findCanonicalParts
Return value
string[]
1 call to Path::findCanonicalParts()
- Path::canonicalize in vendor/
symfony/ filesystem/ Path.php - Canonicalizes the given path.
File
-
vendor/
symfony/ filesystem/ Path.php, line 723
Class
- Path
- Contains utility methods for handling path strings.
Namespace
Symfony\Component\FilesystemCode
private static function findCanonicalParts(string $root, string $pathWithoutRoot) : array {
$parts = explode('/', $pathWithoutRoot);
$canonicalParts = [];
// Collapse "." and "..", if possible
foreach ($parts as $part) {
if ('.' === $part || '' === $part) {
continue;
}
// Collapse ".." with the previous part, if one exists
// Don't collapse ".." if the previous part is also ".."
if ('..' === $part && \count($canonicalParts) > 0 && '..' !== $canonicalParts[\count($canonicalParts) - 1]) {
array_pop($canonicalParts);
continue;
}
// Only add ".." prefixes for relative paths
if ('..' !== $part || '' === $root) {
$canonicalParts[] = $part;
}
}
return $canonicalParts;
}