snapshotpl/tactician-doctrine

使用 Doctrine 的 Tactician 命令插件,如将每个命令包裹在一个事务中

1.2.0 2022-01-11 13:05 UTC

README

Latest Version Software License Build Status Quality Score Total Downloads

此包为使用 Doctrine 组件(ORM 或 DBAL)的 Tactician 插件添加功能,主要特性是将每个命令包裹在一个单独的数据库事务中。

配置

通过 Composer

$ composer require league/tactician-doctrine

接下来,将 ORM\TransactionMiddleware 添加到您的 CommandBus 中

$commandBus = new \League\Tactician\CommandBus(
    [
        new TransactionMiddleware($ormEntityManager)
    ]
);

这样就完成了。现在每个执行的命令都将打开和关闭一个新的事务。

如果一个命令触发更多命令,请注意这些命令将与父命令在同一个事务中运行。建议每个命令作为单独的事务运行,以防止这种情况发生,请使用 Tactician 核心中提供的 LockingMiddleware。这将队列命令直到父命令完成。

如果在处理命令时抛出异常,则事务回滚,EntityManager 关闭,并重新抛出异常。

Symfony 集成

使用 [tactician-bundle] (https://github.com/thephpleague/tactician-bundle) 时,别忘了将 Doctrine 中间件添加到您的 Symfony 配置中

tactician:
    commandbus:
        default:
            middleware:
             - tactician.middleware.locking
             - tactician.middleware.doctrine
             - tactician.middleware.command_handler

测试

$ ./vendor/bin/phpunit

安全性

安全披露信息可以在 主 Tactician 仓库 中找到。

许可

MIT 许可证 (MIT)。更多信息请参阅 许可文件