Path
class Path (View source)
The GenericDatabase\Helpers\Path class provides two static methods for working with file paths:
toAbsolute and isAbsolute. The toAbsolute method converts a relative path to an absolute path,
while the isAbsolute method checks if a given path is absolute or not.
Example Usage:
// Convert a relative path to an absolute path
$relativePath = 'path/to/file.txt';
$absolutePath = Path::toAbsolute($relativePath);
echo $absolutePath;
Output: /full/path/to/file.txt
// Check if a path is absolute
$path = '/full/path/to/file.txt';
$isAbsolute = Path::isAbsolute($path);
echo $isAbsolute ? 'Absolute path' : 'Relative path';
Output: Absolute path
Main functionalities:
- The
toAbsolutemethod converts a relative path to an absolute path by replacing the directory separator with a forward slash ('/') and removing any occurrences of '.' (current directory). - The
isAbsolutemethod checks if a path is absolute by using regular expressions to match the path against a pattern that includes optional wrappers (e.g., 'http://') and a root (e.g., 'C:/') followed by the path itself.
Methods:
toAbsolute(string $path): string: Converts a relative path to an absolute path.isAbsolute(string $path): bool: Checks if a path is absolute.
Methods
static string
toAbsolute(string $path)
Convert path from relative to absolute
static bool
isAbsolute(string $path)
Detect if path is absolute
Details
static string
toAbsolute(string $path)
Convert path from relative to absolute
static bool
isAbsolute(string $path)
Detect if path is absolute