-
-
Notifications
You must be signed in to change notification settings - Fork 0
FilesystemInterface
Defines a standard file system interface with enhanced path resolution.
This interface extends common filesystem operations by ensuring paths can be deterministically resolved to absolute paths before interaction.
- Full name:
\FastForward\DevTools\Filesystem\FilesystemInterface
Checks whether a file or directory exists.
public exists(iterable<string>|string $files, string|null $basePath = null): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$files |
iterable|string | the file(s) or directory(ies) to check |
$basePath |
string|null | the base path used to resolve relative paths |
Return Value:
true if the path exists, false otherwise
Reads the entire content of a file.
public readFile(string $filename, string|null $path = null): stringParameters:
| Parameter | Type | Description |
|---|---|---|
$filename |
string | the target filename to read |
$path |
string|null | the optional base path to resolve the filename against |
Return Value:
the content of the file
Writes content to a file, overriding it if it already exists.
public dumpFile(string $filename, mixed $content, string|null $path = null): voidParameters:
| Parameter | Type | Description |
|---|---|---|
$filename |
string | the filename to write to |
$content |
mixed | the content to write |
$path |
string|null | the optional base path to resolve the filename against |
Copies a file to a target path.
public copy(string $originFile, string $targetFile, bool $overwriteNewerFiles = false): voidParameters:
| Parameter | Type | Description |
|---|---|---|
$originFile |
string | the source file path to copy |
$targetFile |
string | the target file path to create |
$overwriteNewerFiles |
bool | whether newer target files MAY be overwritten |
Changes the permission mode for one or more files.
public chmod(iterable<string>|string $files, int $mode, int $umask = 00, bool $recursive = false): voidParameters:
| Parameter | Type | Description |
|---|---|---|
$files |
iterable|string | the target file paths |
$mode |
int | the permission mode to apply |
$umask |
int | the umask to apply |
$recursive |
bool | whether permissions SHOULD be applied recursively |
Resolves a path or iterable of paths into their absolute path representation.
public getAbsolutePath(iterable<string>|string $files, string|null $basePath = null): iterable<string>|stringIf a relative path is provided, it SHALL be evaluated against the current working directory or the provided $basePath if one is supplied.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$files |
iterable|string | the path(s) to resolve |
$basePath |
string|null | the base path for relative path resolution |
Return Value:
the resolved absolute path(s)
Creates a directory recursively.
public mkdir(iterable<string>|string $dirs, int $mode = 0777, string|null $basePath = null): voidParameters:
| Parameter | Type | Description |
|---|---|---|
$dirs |
iterable|string | the directory path(s) to create |
$mode |
int | the permissions mode (defaults to 0777) |
$basePath |
string|null | the base path for relative path resolution |
Computes the relative path from the base path to the target path.
public makePathRelative(string $path, string|null $basePath = null): stringParameters:
| Parameter | Type | Description |
|---|---|---|
$path |
string | the target absolute or relative path |
$basePath |
string|null | the origin point; defaults to the current working directory |
Return Value:
the computed relative path
Returns the trailing name component of a path.
public basename(string $path, string $suffix = ''): stringParameters:
| Parameter | Type | Description |
|---|---|---|
$path |
string | the path to process |
$suffix |
string | an optional suffix to strip from the returned basename |
Return Value:
the base name of the given path
Returns a parent directory's path.
public dirname(string $path, int $levels = 1): stringParameters:
| Parameter | Type | Description |
|---|---|---|
$path |
string | the path to evaluate |
$levels |
int | the number of parent directories to go up |
Return Value:
the parent path name