nepada / message-bus-doctrine
Doctrine ORM integration for nepada/message-bus
Installs: 10 249
Dependents: 1
Suggesters: 1
Security: 0
Stars: 2
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=8.1.0 <8.5
- doctrine/orm: ^2.13@dev || ^3.0@dev
- doctrine/persistence: ^2.5 || ^3.0
- nepada/message-bus: ^2.0@dev || ^3.0@dev
Requires (Dev)
- composer-runtime-api: ^2.0
- composer/semver: 3.4.3
- doctrine/dbal: >=2.13.3
- nepada/coding-standard: 7.14.1
- nepada/phpstan-nette-tester: 1.2.1
- nette/tester: 2.5.4
- php-parallel-lint/php-parallel-lint: 1.4.0
- phpstan/phpstan: 1.12.7
- phpstan/phpstan-strict-rules: 1.6.1
- shipmonk/phpstan-rules: 3.2.1
- spaze/phpstan-disallowed-calls: 3.5.1
- symfony/cache: ^6.3.12 || ^6.4.3 || ^7.0.3 || >=7.1
- symfony/cache-contracts: >=3.4.2
- symfony/messenger: ^5.4.35 || ^6.3.12 || ^6.4.3 || ^7.0.3 || >=7.1
README
Installation
Via Composer:
$ composer require nepada/message-bus-doctrine
Usage
Recording domain events inside entities
Make your entities implement Nepada\MessageBusDoctrine\Events\ContainsRecordedEvents
(e.g. by using Nepada\MessageBusDoctrine\Events\PrivateEventRecorder
trait) and record domain events inside the entities. The events will be automatically collected and dispatched on flush.
Transaction handling
TransactionMiddleware
wraps the command handling into a database transaction. All changes made by lower layers are automatically flushed and commited, or rolled back on error.
It is highly recommended to use PreventOuterTransactionMiddleware
to ensure there is no outer database transaction started outside of the message bus stack.
Not doing so might lead to unwanted behavior such as dispatching and processing events before the changes made in command handler were actually persisted.
Clearing entity manager
Use ClearEntityManagerMiddleware
to clear entity manager before and/or after the message is handled.
Note: Entity manager will not be cleared when inside active transaction, i.e. the middleware order is important.
Credits
Event recording idea and parts of its implementation are based on simple-bus/doctrine-orm-bridge by Matthias Noback, Cliff Odijk, Ruud Kamphuis.