sbooker / command-bus
命令总线
1.1.0
2024-06-30 11:25 UTC
Requires
- php: ^7.4 || ^8.0
- ramsey/uuid: ^4.0
- sbooker/transaction-manager: ^2.2
- sbooker/workflow: ^1.1
- symfony/property-access: ^5.0 || ^6.0
- symfony/serializer: ^5.0 || ^6.0
Requires (Dev)
- doctrine/cache: ^1.12
- doctrine/dbal: ^3.8 || ^4.0
- doctrine/orm: ^2.9 || ^3.0
- phpunit/phpunit: ^9.0
- psr/container: 1.0.0
- ramsey/uuid-doctrine: ^1.6
- sbooker/console: ^1.1
- sbooker/doctrine-transaction-handler: ^2.2
- sbooker/enumerable-doctrine: ^1.1
Suggests
- doctrine/dbal: ^3.8
- doctrine/orm: If you want use DB persistence with Doctrine
- psr/container: If you want use container registry implementation
- ramsey/uuid-doctrine
- sbooker/console: If you want use debug commands
- sbooker/doctrine-enumerable-type
- sbooker/doctrine-transaction-handler
- sbooker/event-loop-worker: If you want handle command in background process
README
并通过 Doctrine ORM 实现的持久化
安装
通过 Composer 安装
composer require sbooker/command-bus
嵌套事务
端点可以使用事务。强烈建议使用 Sbooker/TransactionManager 来实现。
您需要确保首先执行所有检查并抛出异常。
然后才修改实体的状态。
使用 Symfony 和 Doctrine 的示例(不带包)
重要!
命令总线的内置持久化层需要 doctrine/dbal:^3.8 和支持 SELECT FOR UPDATE SKIP LOCKED(MySQL 8.0+、PostgreSQL 9.5+)的数据库。
安装建议库
composer require sbooker/doctrine-enumerable-type \ sbooker/doctrine-transaction-handler \ ramsey/uuid-doctrine \ doctrine/dbal:^3.8
要使用默认配置,请按以下方式配置
### config/packages/sbooker_command_bus.yaml doctrine: dbal: types: command_status: Sbooker\CommandBus\Infrastructure\Persistence\Mapping\StatusType orm: mappings: SbookerCommands: type: xml prefix: Sbooker\CommandBus dir: '%kernel.project_dir%/vendor/sbooker/command-bus/src/Infrastructure/Persistence/Mapping' is_bundle: false services: Sbooker\CommandBus\CommandBus: class: Sbooker\CommandBus\PersistentCommandBus arguments: - '@Sbooker\CommandBus\Normalizer' - '@Sbooker\TransactionManager\TransactionManager' - '@Sbooker\CommandBus\ReadStorage' Sbooker\CommandBus\Normalizer: class: Sbooker\CommandBus\Normalization\SymfonySerializerNormalizer arguments: - '@Sbooker\CommandBus\NameGiver' - '@serializer' Sbooker\CommandBus\Denormalizer: class: Sbooker\CommandBus\Normalization\SymfonySerializerDenormalizer arguments: - '@Sbooker\CommandBus\NameGiver' - '@serializer' Sbooker\CommandBus\Registry: class: Sbooker\CommandBus\Registry\Containerized\ContainerizedRegistry arguments: - '@command_bus.registry.endpoint_container' - '@command_bus.registry.timeout_calculator_container' command_bus.registry.endpoint_container: class: Sbooker\CommandBus\Registry\Containerized\ContainerAdapter arguments: - '@service_container' - ~ - ## command name to endpoint map command_bus.registry.timeout_calculator_container: class: Sbooker\CommandBus\Registry\Containerized\ContainerAdapter arguments: - '@service_container' - 'command_bus.timeout_calculator.default' - ## command name to timeout calculator map command_bus.timeout_calculator.default: public: true class: Sbooker\CommandBus\TimeoutCalculator\Fix arguments: - 1 - 3 command_bus.timeout_calculator.external: public: true class: Sbooker\CommandBus\TimeoutCalculator\BinExp arguments: - 10 Sbooker\CommandBus\NameGiver: class: Sbooker\CommandBus\NameGiver\ClassNameMap arguments: - ## FQCN to command name map Sbooker\CommandBus\ReadStorage: alias: Sbooker\CommandBus\Infrastructure\Persistence\DoctrineRepository Sbooker\CommandBus\Infrastructure\Persistence\DoctrineRepository: class: Sbooker\CommandBus\Infrastructure\Persistence\DoctrineRepository factory: [ '@doctrine', getRepository ] arguments: - Sbooker\CommandBus\Command
许可证
见 LICENSE 文件。