webimpress/safe-writer

安全写入文件的工具,以避免竞态条件

2.2.0 2021-04-19 16:34 UTC

README

Unit Tests Coding Standards Static Analysis Coverage Status

安全写入文件,以避免在短时间内多次写入同一文件时发生竞态条件。

安装

使用 composer

composer require webimpress/safe-writer

使用方法

use Webimpress\SafeWriter\FileWriter;

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

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

如果出现问题,将抛出异常(Webimpress\SafeWriter\Exception\ExceptionInterface 实例)。