webimpress/safe-writer
Safely and atomically write files in PHP: create temp files, write/flush, then rename into place to avoid partial writes. Handles permissions, directories, and errors for reliable config/cache/log output in CLI and web apps.
\Throwable extension for package-specific exception marker Webimpress\SafeWriter\Exception\ExceptionInterface.#5 changes all exception classes to be non-instantiable and all theirs public method to be internal. Library exceptions can only be caught in the user code, cannot be thrown.
#5 changes all method declarations to have type hints and return types.
Adds function to safely writing files to avoid race conditions when the same file is written multiple times in a short time period, and errors on reading not fully written files. Example usage:
use Webimpress\SafeWriter\FileWriter;
$targetFile = __DIR__ . '/config-cache.php';
$content = "<?php\nreturn " . var_export($data, true) . ';';
FileWriter::writeFile($targetFile, $content, 0666);
How can I help you explore Laravel packages today?