final class DirectoryManager implements DirectoryManagerInterface (View source)

Performs local directory and file-tree operations while translating native failures to filesystem contracts.

Methods

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

Creates a directory including any missing parent directories.

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
void
delete(string $path)

Deletes a file, symbolic link, or directory.

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

Lazily yields entries without following linked directories.

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

Lazily yields filesystem metadata without following linked directories.

find(string $pattern, string $path)

Lazily yields direct matches without allowing the pattern to leave the base directory.

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

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

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

stream

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

Lazily yields entries without following linked directories.

Parameters

string $path
bool $recursive

Return Value

Generator

Exceptions

FilesystemException

tree

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

Lazily yields filesystem metadata without following linked directories.

Parameters

string $path
bool $recursive

Return Value

Generator

Exceptions

FilesystemException

find

Generator find(string $pattern, string $path)

Lazily yields direct matches without allowing the pattern to leave the base directory.

Parameters

string $pattern
string $path

Return Value

Generator

Exceptions

FilesystemException