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 toAbsolute method 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 isAbsolute method 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

Parameters

string $path

The relative path

Return Value

string

The absolute path

static bool isAbsolute(string $path)

Detect if path is absolute

Parameters

string $path

The path

Return Value

bool

True if the path is absolute, false otherwise

Exceptions

Exceptions