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

Breadcrumb

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

function Path::isBasePath

Returns whether a path is a base path of another path.

Dot segments ("." and "..") are removed/collapsed and all slashes turned into forward slashes.

```php Path::isBasePath('/symfony', '/symfony/css'); // => true

Path::isBasePath('/symfony', '/symfony'); // => true

Path::isBasePath('/symfony', '/symfony/..'); // => false

Path::isBasePath('/symfony', '/puli'); // => false ```

File

vendor/symfony/filesystem/Path.php, line 707

Class

Path
Contains utility methods for handling path strings.

Namespace

Symfony\Component\Filesystem

Code

public static function isBasePath(string $basePath, string $ofPath) : bool {
    $basePath = self::canonicalize($basePath);
    $ofPath = self::canonicalize($ofPath);
    // Append slashes to prevent false positives when two paths have
    // a common prefix, for example /base/foo and /base/foobar.
    // Don't append a slash for the root "/", because then that root
    // won't be discovered as common prefix ("//" is not a prefix of
    // "/foobar/").
    return str_starts_with($ofPath . '/', rtrim($basePath, '/') . '/');
}

API Navigation

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