final class Filesystem (View source)

Exposes the framework's filesystem collaborators through one facade while retaining their typed failure contracts.

Methods

__construct(DirectoryManagerInterface $directoryManager, FileManagerInterface $fileManager, LockManagerInterface $lockManager)

Composes the filesystem contracts exposed through this immutable facade.

Returns the collaborator responsible for filesystem mutations and traversal.

Returns the collaborator responsible for file reads and metadata.

Returns the collaborator responsible for callback lock lifecycles.

void
create(string $path, int $mode = 0775)

Creates a directory and any missing parents.

void
void
delete(string $path)

Deletes a file, link, or directory tree without following linked directories.

void
void
copy(string $src, string $dst, bool $overwrite = false)

Copies a regular file or directory without following symbolic links.

void
void
write(string $file, string $data, int|null $mode = 0666)

Atomically publishes file contents from a same-directory temporary file.

void
void
move(string $source, string $target)

Atomically renames a file within one local filesystem.

void
stream(string $path, bool $recursive = true)

Lazily yields direct entries or a complete tree without following linked directories.

find(string $pattern, string $path)

Lazily yields direct glob matches constrained to the selected directory.

tree(string $path, bool $recursive = true)

Lazily yields entry metadata without following linked directories.

string
read(string $file)

Reads the complete contents of a regular file.

string
int
size(string $file)

Returns the size of a regular file in bytes.

int
int
modified(string $file)

Returns the modification time of an existing filesystem path.

int
string
hash(string $file, string $algo = 'sha256')

Hashes a regular file with an explicitly supported algorithm.

string
string
mime(string $file)

Detects the MIME type of a regular file.

string
int
permissions(string $file)

Returns the permission bits of an existing filesystem path.

int
mixed
lock(string $file, callable $callback)

Executes a callback while holding an exclusive lock.

mixed

Details

__construct

__construct(DirectoryManagerInterface $directoryManager, FileManagerInterface $fileManager, LockManagerInterface $lockManager)

Composes the filesystem contracts exposed through this immutable facade.

Parameters

DirectoryManagerInterface $directoryManager
FileManagerInterface $fileManager
LockManagerInterface $lockManager

getDirectoryManager

DirectoryManagerInterface getDirectoryManager()

Returns the collaborator responsible for filesystem mutations and traversal.

getFileManager

FileManagerInterface getFileManager()

Returns the collaborator responsible for file reads and metadata.

Return Value

FileManagerInterface

getLockManager

LockManagerInterface getLockManager()

Returns the collaborator responsible for callback lock lifecycles.

Return Value

LockManagerInterface

create

void create(string $path, int $mode = 0775)

Creates a directory and any missing parents.

Parameters

string $path
int $mode

Return Value

void

Exceptions

FilesystemException

delete

void delete(string $path)

Deletes a file, link, or directory tree without following linked directories.

Parameters

string $path

Return Value

void

Exceptions

FilesystemException

copy

void copy(string $src, string $dst, bool $overwrite = false)

Copies a regular file or directory without following symbolic links.

Parameters

string $src
string $dst
bool $overwrite

Return Value

void

Exceptions

FilesystemException

write

void write(string $file, string $data, int|null $mode = 0666)

Atomically publishes file contents from a same-directory temporary file.

Parameters

string $file
string $data
int|null $mode

Return Value

void

Exceptions

FilesystemException

move

void move(string $source, string $target)

Atomically renames a file within one local filesystem.

Parameters

string $source
string $target

Return Value

void

Exceptions

FilesystemException

stream

Generator stream(string $path, bool $recursive = true)

Lazily yields direct entries or a complete tree without following linked directories.

Parameters

string $path
bool $recursive

Return Value

Generator

Exceptions

FilesystemException

find

Generator find(string $pattern, string $path)

Lazily yields direct glob matches constrained to the selected directory.

Parameters

string $pattern
string $path

Return Value

Generator

Exceptions

FilesystemException

tree

Generator tree(string $path, bool $recursive = true)

Lazily yields entry metadata without following linked directories.

Parameters

string $path
bool $recursive

Return Value

Generator

Exceptions

FilesystemException

read

string read(string $file)

Reads the complete contents of a regular file.

Parameters

string $file

Return Value

string

Exceptions

FilesystemException

size

int size(string $file)

Returns the size of a regular file in bytes.

Parameters

string $file

Return Value

int

Exceptions

FilesystemException

modified

int modified(string $file)

Returns the modification time of an existing filesystem path.

Parameters

string $file

Return Value

int

Exceptions

FilesystemException

hash

string hash(string $file, string $algo = 'sha256')

Hashes a regular file with an explicitly supported algorithm.

Parameters

string $file
string $algo

Return Value

string

Exceptions

FilesystemException

mime

string mime(string $file)

Detects the MIME type of a regular file.

Parameters

string $file

Return Value

string

Exceptions

FilesystemException

permissions

int permissions(string $file)

Returns the permission bits of an existing filesystem path.

Parameters

string $file

Return Value

int

Exceptions

FilesystemException

lock

mixed lock(string $file, callable $callback)

Executes a callback while holding an exclusive lock.

Parameters

string $file
callable $callback

Return Value

mixed

Exceptions

FilesystemException