Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Path.php

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\Filesystem

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal