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
-
isAbsolute() public static
Checks if a path is absolute.
-
join() public static
Joins path segments together using the correct directory separator.
-
makeAbsolute() public static
Makes a path absolute, using a base path if the given path is not already absolute, and resolves any
.and..segments in the result. -
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.
-
resolveDotSegments() protected static
Resolves
.and..segments in an absolute, forward-slash-normalized path.Segments that would go above the root (e.g. an extra
..at the root level) are simply dropped, since there is nothing above the root to resolve to.
Method Detail
isAbsolute() ¶ public static
isAbsolute(string $path): bool
Checks if a path is absolute.
Parameters
-
string$path The path to check
Returns
boolTrue if the path is absolute
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
makeAbsolute() ¶ public static
makeAbsolute(string $path, string $from): string
Makes a path absolute, using a base path if the given path is not already absolute,
and resolves any . and .. segments in the result.
Parameters
-
string$path The path to make absolute
-
string$from The base path to use when $path is relative. Expected to already be absolute.
Returns
stringThe absolute, resolved 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
resolveDotSegments() ¶ protected static
resolveDotSegments(string $path): string
Resolves . and .. segments in an absolute, forward-slash-normalized path.
Segments that would go above the root (e.g. an extra .. at the root level)
are simply dropped, since there is nothing above the root to resolve to.
Parameters
-
string$path The absolute path to resolve
Returns
stringThe resolved path