2017 © Pedro Peláez
 

library event-store

Event store layer to help us (Cocoders) to implement event sourcing in our projects

image

cocoders/event-store

Event store layer to help us (Cocoders) to implement event sourcing in our projects

  • Monday, April 4, 2016
  • by l3l0
  • Repository
  • 3 Watchers
  • 12 Stars
  • 900 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Quite basic and simple Event Store abstraction layer

Travis build, (*1)

Event store layer to help us - Cocoders to implement event sourcing in our projects. It is quite simple (or event stupid) abstraction layer (yunno KISS), (*2)

Requirements

PHP >= 7.0, (*3)

Installation

Package can be installed using composer composer require cocoders/event-store, (*4)

Usage

Library provides bunch of interfaces and about 5 concrete classes for handling domain events., (*5)

What you need to do in order to setup this event store with your project? Follow those 5 steps., (*6)

  1. Step 1 - define you aggregate In your aggregate you need implement Cocoders\EventStore\AggregateRoot interface (you can use Cocoders\EventStore\AggregateRootBehavior trait if tou want). Example: Example Domain Invoice Aggregate, (*7)

  2. Step 2 - define own events and use it in aggregate You should define new event classes and use those events in you aggregate, (*8)

  3. Step 3 - implement own EventStore You need to create concrete implementation of Cocoders\EventStore\EventStore interface, using your favorite db engine ;) Example: Json File EventStore, (*9)

  4. Step 4 - do some operation on aggregate and add fresh events from Aggregate to event store, and commit event store., (*10)

Examples:, (*11)

    $eventStore = new MyEventStore();
    $invoice = Invoice::issueInvoice(
        Invoice\Id::generate();
        $command->getSeller(),
        $command->getBuyer(),
        $command->maxItemNumber
    );
    $eventStore->apply(new EventStream\Name(Invoice::class), $invoice->getRecordedEvents());
    $eventStore->commit();
  1. Step 5 - define own projections. As you can see in example, invoice aggregate does not have many "getters". You should generate read model using projection instead of using getters. Projection is basically event subscriber which can react to event by chaging read model. To use event subscriber you need to use EventBus:
  $eventStore = new MyEventStore(); 
  $eventSubscribers = new EventSubscribers();
  $eventBus = new EventBus($eventSubscribers);
  $projectionManager = new ProjectionManager($eventSubscribers);
  $projectionManager->registerProjection(
      'InvoiceIssued',
      new MyProjection()
  );
  $newEventsStream = $eventStore->findUncommited(new EventStream\Name(Invoice::class));
  $eventStore->commit();
  $eventStore->notify($newEventsStream); //now event bus will notify projections as well

Development and tests

To develop this lib we are using docker and docker-compose. After installation of those you should run:, (*12)

    docker-compose up
    docker-compose run eventstore bash

Then on docker console run:, (*13)

composer install
php bin/phpspec run -fpretty
php bin/phpunit

The Versions

04/04 2016

dev-master

9999999-dev

Event store layer to help us (Cocoders) to implement event sourcing in our projects

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

10/03 2016

0.1.1

0.1.1.0

Event store layer to help us (Cocoders) to implement event sourcing in our projects

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

03/03 2016

0.1.0

0.1.0.0

Event store layer to help us (Cocoders) to implement event sourcing in our projects

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires