snapshotpl / tactician-doctrine
使用 Doctrine 的 Tactician 命令插件,如将每个命令包裹在一个事务中
1.2.0
2022-01-11 13:05 UTC
Requires
- php: >=7.1
- doctrine/dbal: ^2.4 || ^3.1.5
- league/tactician: ^1.1
Requires (Dev)
- doctrine/orm: ^2.4
- mockery/mockery: ^1.3.5
- phpunit/phpunit: ^7.5.20 || ^9.5.10
- squizlabs/php_codesniffer: ^3.6.2
- yoast/phpunit-polyfills: ^1.0
Suggests
- doctrine/orm: Required if you need to use ORM Transaction Middleware
This package is auto-updated.
Last update: 2024-09-11 18:59:20 UTC
README
此包为使用 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)。更多信息请参阅 许可文件。