danbettles / temper
驯服你的临时文件。Temper 提供了一种更平滑的方式来处理 PHP 中的临时文件。
v3.0.0
2024-08-10 09:53 UTC
Requires
- php: ^8.1.28
Requires (Dev)
- danbettles/codesniffer-standard: ^2.0
- phpstan/phpstan: ^1.11
- phpunit/phpunit: ^11.1.3
- squizlabs/php_codesniffer: ^3.9.2
README
Temper 提供了一种更平滑的方式来处理 PHP 中的临时文件。
使用方法
有两种使用方法
- 消费临时文件:一次性创建、使用和删除临时文件
- 分步骤创建和删除临时文件
消费临时文件
$temper = new Temper('/path/to/tmp/dir'); $temper->consumeFile(function (SplFileInfo $tempFileinfo): void { // Do something with temp-file }); // Temp-file gone $temper->consumeFile(function (SplFileInfo $tempFileinfo): void { // Do something with `.jpg` temp-file }, 'jpg'); // Temp-file gone
分步骤创建和删除
注意
由于 Temper 实例在其生命结束时将自动清理它所知道的任何剩余的临时文件,因此您可能永远不会需要手动调用 cleanUp()。
$temper = new Temper('/path/to/tmp/dir'); $tempFileWithoutExtension = $temper->createFile(); $tempImageFile = $temper->createFile('jpg'); // Removes *all* remaining temp-files created by the Temper instance $temper->cleanUp();
安装
使用 Composer 安装
composer require danbettles/temper