webimpress/safe-writer

Tool to write files safely, to avoid race conditions

Fund package maintenance!
michalbundyra

Installs: 12 241 478

Dependents: 7

Suggesters: 0

Security: 0

Stars: 362

Watchers: 6

Forks: 7

Open Issues: 3

2.2.0 2021-04-19 16:34 UTC

README

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.