src/Path.php
public static function isBasePath($basePath, $ofPath)
    {
        Assert::string($basePath, 'The base path must be a string. Got: %s');

        $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 0 === strpos($ofPath.'/', rtrim($basePath, '/').'/');
    }
public static function isBasePath($basePath, $ofPath)
    {
        Assert::string($basePath, 'The base path must be a string. Got: %s');

        $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 0 === strpos($ofPath.'/', rtrim($basePath, '/').'/');
    }
public static function isBasePath ( $ basePath , $ ofPath ) { Assert :: string ( $ basePath , 'The base path must be a string. Got: %s' ) ; $ 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 0 === strpos ( $ ofPath . '/' , rtrim ( $ basePath , '/' ) . '/' ) ; }
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('/webmozart', '/webmozart/css');
// => true

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

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

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

@param string $basePath The base path to test.
@param string $ofPath   The other path.

@return bool Whether the base path is a base path of the other path.

@since 1.0 Added method.
@since 2.0 Method now fails if $basePath or $ofPath is not a string.
Returns whether a path is a base path of another path .