Skip to content

webimpress/safe-writer

Folders and files

NameName
Last commit message
Last commit date
Mar 10, 2025
Apr 19, 2021
Nov 23, 2023
Oct 28, 2019
Nov 15, 2019
Aug 25, 2020
Apr 19, 2021
Apr 20, 2021
Feb 9, 2022
Apr 17, 2023
Mar 3, 2025
Apr 19, 2021
Apr 19, 2021
Mar 30, 2023

Repository files navigation

Webimpress Safe Writer

Unit Tests Coding Standards Static Analysis Coverage Status

Write files safely to avoid race conditions when the same file is written multiple times in a short time period.

Installation

Using composer:

composer require webimpress/safe-writer

Usage

use Webimpress\SafeWriter\FileWriter;

$targetFile = __DIR__ . '/target-file.php';
$content = "<?php\nreturn " . var_export($data, true) . ';';

FileWriter::writeFile($targetFile, $content);

If something goes wrong exception (instance of Webimpress\SafeWriter\Exception\ExceptionInterface) will be thrown.