interface DirectoryManagerInterface (View source)

Defines local filesystem mutations and lazy directory traversal with typed failures instead of native warnings.

Methods

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

Creates a directory including any missing parent directories.

void
void
delete(string $path)

Deletes a file, symbolic link, or directory.

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

Copies a regular file or directory to the target path.

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

Writes data to a file and creates the target directory if needed.

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

Atomically publishes a fully written file at its final path on the same local filesystem.

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

Returns a lazy list of directory entries.

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

Walks a directory and returns entries as SplFileInfo instances.

find(string $pattern, string $path)

Finds entries in a directory using a glob pattern.

Details

create

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

Creates a directory including any missing parent directories.

The operation is idempotent: if the directory already exists, the method does nothing.

Parameters

string $path
int $mode

Return Value

void

Exceptions

FilesystemException

delete

void delete(string $path)

Deletes a file, symbolic link, or directory.

If the path is a directory, its contents are removed recursively without following symbolic links. Deleting a symbolic link removes only the link. If the path does not exist, the method does nothing.

Parameters

string $path

Return Value

void

Exceptions

FilesystemException

copy

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

Copies a regular file or directory to the target path.

Directories are copied recursively without following symbolic links; a symbolic link source or entry is rejected. Files are published from a same-directory temporary file, so a failed file copy preserves an existing target. If overwrite is disabled, an existing target is rejected, but this check is not a concurrent compare-and-swap.

A newly created target directory is removed after a failed recursive copy when possible. Merging into an existing directory may leave entries copied before the failure.

Parameters

string $src
string $dst
bool $overwrite

Return Value

void

Exceptions

FilesystemException

write

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

Writes data to a file and creates the target directory if needed.

Data is written to a same-directory temporary file and renamed into place, so failures before publication preserve an existing file. This guarantees atomic visibility on the local filesystem, not crash durability. The mode parameter controls the resulting file permissions. A null mode preserves an existing target's permission bits and otherwise keeps the creation mode.

Parameters

string $file
string $data
int|null $mode

Return Value

void

Exceptions

FilesystemException

move

void move(string $source, string $target)

Atomically publishes a fully written file at its final path on the same local filesystem.

Parameters

string $source
string $target

Return Value

void

Exceptions

FilesystemException

stream

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

Returns a lazy list of directory entries.

The generator key is the entry name and the value is its absolute path. Symbolic links are yielded as entries inside the scanned tree and linked directories are not followed. Depending on the recursive flag, only the first level or the full tree is scanned. Linked directories are yielded but never traversed.

Parameters

string $path
bool $recursive

Return Value

Generator

Exceptions

FilesystemException

tree

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

Walks a directory and returns entries as SplFileInfo instances.

Depending on the recursive flag, only the first level or the full tree is scanned.

Parameters

string $path
bool $recursive

Return Value

Generator

Exceptions

FilesystemException

find

Generator find(string $pattern, string $path)

Finds entries in a directory using a glob pattern.

The search is limited to the given directory and is not recursive. Patterns containing path separators are rejected. Matching symbolic links are returned without being followed.

Parameters

string $pattern
string $path

Return Value

Generator

Exceptions

FilesystemException