Class Path
Path utility class for cross-platform path manipulation.
Provides static methods for normalizing, joining, and working with filesystem paths in a platform-independent way.
Method Summary
-
join() public static
Joins path segments together using the correct directory separator.
-
makeRelative() public static
Makes a path relative to a base path.
-
matches() public static
Checks if a path matches a glob pattern.
-
normalize() public static
Normalizes a path by converting directory separators to forward slashes and removing redundant separators.
Method Detail
join() ¶ public static
join(string ...$segments): string
Joins path segments together using the correct directory separator.
Parameters
-
string...$segments Path segments to join
Returns
stringThe joined path
makeRelative() ¶ public static
makeRelative(string $path, string $from): string
Makes a path relative to a base path.
Parameters
-
string$path The absolute path to make relative
-
string$from The base path to make relative from
Returns
stringThe relative path
matches() ¶ public static
matches(string $pattern, string $path): bool
Checks if a path matches a glob pattern.
Parameters
-
string$pattern The glob pattern
-
string$path The path to check
Returns
boolTrue if the path matches the pattern
normalize() ¶ public static
normalize(string $path, bool $trailing = false): string
Normalizes a path by converting directory separators to forward slashes and removing redundant separators.
Parameters
-
string$path The path to normalize
-
bool$trailing optional Whether to preserve trailing slashes
Returns
stringThe normalized path