IFileSystem
in
Interface for file system operations abstraction.
Provides a testable abstraction over file system operations. Implementations can be real file system access for production or in-memory systems for testing.
Table of Contents
Methods
- fileExists() : bool
- Check if a file exists
- getcwd() : string|false
- Get current working directory
- glob() : array<string|int, mixed>|false
- Find pathnames matching a pattern
- isDir() : bool
- Check if path is a directory
- mkdir() : bool
- Create a directory
- readFile() : string|false
- Read entire file contents
- realpath() : string|false
- Get absolute path (resolve symlinks, relative paths)
- rmdir() : bool
- Remove a directory
- scandir() : array<string|int, mixed>|false
- List files and directories in a directory
- unlink() : bool
- Delete a file
- writeFile() : int|false
- Write data to file
Methods
fileExists()
Check if a file exists
public
fileExists(string $path) : bool
Parameters
- $path : string
-
File path
Return values
bool —True if file exists, false otherwise
getcwd()
Get current working directory
public
getcwd() : string|false
Return values
string|false —Current directory or false on failure
glob()
Find pathnames matching a pattern
public
glob(string $pattern) : array<string|int, mixed>|false
Parameters
- $pattern : string
-
Pattern to match (e.g., "/path/.txt", "/path/**/.php")
Return values
array<string|int, mixed>|false —Array of matching paths or false on failure
isDir()
Check if path is a directory
public
isDir(string $path) : bool
Parameters
- $path : string
-
Directory path
Return values
bool —True if directory exists, false otherwise
mkdir()
Create a directory
public
mkdir(string $path[, int $permissions = 0755 ][, bool $recursive = true ]) : bool
Parameters
- $path : string
-
Directory path
- $permissions : int = 0755
-
Directory permissions (default 0755)
- $recursive : bool = true
-
Create parent directories if needed (default true)
Return values
bool —True on success, false on failure
readFile()
Read entire file contents
public
readFile(string $path) : string|false
Parameters
- $path : string
-
File path
Return values
string|false —File contents or false on failure
realpath()
Get absolute path (resolve symlinks, relative paths)
public
realpath(string $path) : string|false
Parameters
- $path : string
-
Path to resolve
Return values
string|false —Resolved absolute path or false on failure
rmdir()
Remove a directory
public
rmdir(string $path) : bool
Parameters
- $path : string
-
Directory path
Return values
bool —True on success, false on failure
scandir()
List files and directories in a directory
public
scandir(string $path) : array<string|int, mixed>|false
Parameters
- $path : string
-
Directory path
Return values
array<string|int, mixed>|false —Array of filenames or false on failure
unlink()
Delete a file
public
unlink(string $path) : bool
Parameters
- $path : string
-
File path
Return values
bool —True on success, false on failure
writeFile()
Write data to file
public
writeFile(string $path, string $data) : int|false
Parameters
- $path : string
-
File path
- $data : string
-
Data to write
Return values
int|false —Number of bytes written or false on failure