libriciel/cakephp-filesystem

具有事务的文件操作

安装次数: 1,555

依赖项: 2

建议者: 1

安全: 0

类型:cakephp-plugin

2.2.2 2023-10-10 14:41 UTC

This package is auto-updated.

Last update: 2024-08-29 12:43:41 UTC


README

build status coverage report

描述

允许处理文件,带有或没有事务系统。

安装

composer config repositories.libriciel/cakephp-filesystem git https://gitlab.libriciel.fr/lganee/cakephp-filesystem.git
composer require libriciel/cakephp-filesystem ~1.0

为了使用翻译文件(异常和Shell),您可以向您的应用程序路径中添加插件路径

Configure::write('App.paths.locales', [
    APP . 'Locale' . DS,
    ROOT.DS.'vendor'.DS.'libriciel'.DS.'cakephp-filesystem'.DS.'src'.DS.'Locale'.DS
]);

使用

在PSR-4中,添加 use Libriciel\Filesystem\Utility\Filesystem;

事务

Filesystem::begin();
Filesystem::remove($files);
if ($condition) {
    Filesystem::commit();
} else {
    Filesystem::rollback();
}

脚本停止时的回滚

Filesystem::begin();
Filesystem::rename($filename, $newFilename);
exit; // rollback

支持多个事务级别

Filesystem::begin();
Filesystem::rename($tmpFile1, $tmpFile2, true);

    Filesystem::begin('nested');
    Filesystem::rename($tmpFile2, $tmpFile3, true);
    if ($cond) {
        Filesystem::rollback('nested');
    }

if ($cond) {
    Filesystem::rollback();
}

Shell

存在一个shell来执行未完成的回滚操作(例如:服务器突然停止)。请与cakephp二进制文件一起使用

bin/cake \\Libriciel\\Filesystem\\Shell\\FilesystemShell

Shred

在Unix系统上,可以使用shred程序逐位删除文件。要使用Filesystem,您需要设置配置密钥 Configure::write('FilesystemUtility.useShred', true)。您可以在任何时候通过调用来更改此值

Filesystem::useShred($bool);

测试

vendor/bin/phpunit