mnc-ddd/doctrine-event-store

A Doctrine ORM implementation of an Event Store

1.0.0 2018-10-13 20:00 UTC

README

A Doctrine ORM implementation of an Event Store

Build Status Maintainability Test Coverage Latest Stable Version Latest Unstable Version Total Downloads License

Introduction

Some application require persisting occurred domain events. This doctrine implementation will allow you to store domain events using Doctrine ORM. Once persisted, these events can be fetched by other systems.

Installation

composer require mnc-ddd/doctrine-event-store

Documentation

This event store is made to work with the mnc-ddd/aggregate library. You can easily persist domain events in any database engine supported by Doctrine ORM.

Persisting the Event

In order to persist the event, you must create an instance of StoredEvent. This is really easy if you have an instance of DomainEvent available.

<?php

use MNC\PhpDdd\Domain\Event\StoredEvent;

$storedEvent = StoredEvent::fromDomainEvent($aDomainEvent);

$eventStore->append($storedEvent);

The StoredEvent normalizes some of the domain event fields, and also stored the original event as a serialized object, so you can then have the original event data in a form of an object if you need it.

As in the mnc-ddd/event-store api, you can fetch all the events, events from a certain id, events of a certain aggregateRoot, and events that affected certain actor.

If you need to query for an specific event payload data, you must take a look to syslogic/doctrine-json-functions and implement your own query methods extending the event store class, and using those json functions.

Registering the Mappings

The mappings are in the Simplified XML format provided by Doctrine. If you don't know how to work with it, take a look at their documentation on the subject. Here's a simple sample bootstrapping though:

<?php

$config = Setup::createConfiguration(true);
$config->setMetadataDriverImpl(new SimplifiedXmlDriver([
    'vendor/mnc-ddd/doctrine-event-store/src/Infrastructure/Persistence/DoctrineORM/Mappings' => 'MNC\PhpDdd\Domain',
]));

return EntityManager::create($conn, $config);

As you can see, it is a pretty long directory. We hope to fix this in a future release. In the meantime, you can always symlink that path to provide a shorter one.

Future Features

  • Add support for Doctrine ODM.