wws-aslan/tactician-doctrine

为使用Doctrine的Tactician命令插件,例如将每个命令封装在事务中

v1.1.0 2024-05-10 11:47 UTC

This package is auto-updated.

Last update: 2024-09-10 12:54:21 UTC


README

Latest Version Software License Build Status Quality Score Total Downloads

此包为使用Doctrine组件(ORM或仅DBAL)与Tactician一起使用添加插件。主要功能是能够将每个命令封装在单独的数据库事务中。

设置

通过Composer

$ composer require wws-aslan/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)。有关更多信息,请参阅许可证文件