DirectoryManager
final class DirectoryManager implements DirectoryManagerInterface (View source)
Performs local directory and file-tree operations while translating native failures to filesystem contracts.
Methods
Creates a directory including any missing parent directories.
Copies a regular file or directory to the target path.
Writes data to a file and creates the target directory if needed.
Atomically publishes a fully written file at its final path on the same local filesystem.
Deletes a file, symbolic link, or directory.
Lazily yields entries without following linked directories.
Lazily yields filesystem metadata without following linked directories.
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.
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.
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.
move
void
move(string $source, string $target)
Atomically publishes a fully written file at its final path on the same local filesystem.
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.
stream
Generator
stream(string $path, bool $recursive = true)
Lazily yields entries without following linked directories.
tree
Generator
tree(string $path, bool $recursive = true)
Lazily yields filesystem metadata without following linked directories.
find
Generator
find(string $pattern, string $path)
Lazily yields direct matches without allowing the pattern to leave the base directory.