Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
69 lines (44 sloc) 1.74 KB

DoctrineDBALBridge

This package provides a command bus middleware that can be used to integrate SimpleBus/MessageBus with Doctrine DBAL.

It provides an easy way to wrap command handling in a database transaction.

@TODO The intro should explain what it does.

Getting started

Installation

Using Composer:

composer require simple-bus/doctrine-dbal-bridge

Preparations

To use the middleware provided by the library, set up a command bus, if you didn't already do this:

use SimpleBus\Message\Bus\Middleware\MessageBusSupportingMiddleware;

$commandBus = new MessageBusSupportingMiddleware();
...

Make sure to also properly set up a Doctrine connection:

// $connection is an instance of Doctrine\DBAL\Driver\Connection
$connection = ...;

Transactions

It is generally a good idea to wrap command handling in a database transaction. If you want to do this, add the WrapsMessageHandlingInTransaction middleware to the command bus. Provide an instance of the Doctrine Connection interface that you want to use.

use SimpleBus\DoctrineDBALBridge\MessageBus\WrapsMessageHandlingInTransaction;

// $connection is an instance of Doctrine\DBAL\Driver\Connection
$connection = ...;

$transactionalMiddleware = new WrapsMessageHandlingInTransaction($connection);

$commandBus->addMiddleware($transactionalMiddleware);

When an exception is thrown, the transaction will be rolled back. If not, the transaction is committed.