sbooker / command-bus
Command bus
Installs: 5 917
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
Open Issues: 0
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
And persistent via Doctrine ORM implementation
Installation
Install via Composer:
composer require sbooker/command-bus
Nested transactions
Enpoints may use transactions. Strongly recommends use Sbooker/TransactionManager for it.
You need to make sure that firstly do all checks are and throws exceptions.
And only then mutates state of entities.
Example usage with Symfony and Doctrine (without bundle)
Important!
Build-in realization persistence layer of command bus require doctrine/dbal:^3.8 and database supports SELECT FOR UPDATE SKIP LOCKED (MySQL 8.0+, PostgreSQL 9.5+)
Install suggest libraries:
composer require sbooker/doctrine-enumerable-type \ sbooker/doctrine-transaction-handler \ ramsey/uuid-doctrine \ doctrine/dbal:^3.8
To use default configuration configure as bellow:
### 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
See LICENSE file.