Doctrine ORM integration for nepada/message-bus

v2.1.2 2022-09-24 19:55 UTC


Build Status Coverage Status Downloads this Month Latest stable


Via Composer:

$ composer require nepada/message-bus-doctrine


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.


Event recording idea and parts of its implementation are based on simple-bus/doctrine-orm-bridge by Matthias Noback, Cliff Odijk, Ruud Kamphuis.