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\FilesystemCode
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, '/') . '/');
}