Download the PHP package cocoders/event-store without Composer
On this page you can find all versions of the php package cocoders/event-store. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cocoders/event-store
More information about cocoders/event-store
Files in cocoders/event-store
Package event-store
Short Description Event store layer to help us (Cocoders) to implement event sourcing in our projects
License MIT
Informations about the package event-store
Quite basic and simple Event Store abstraction layer
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)
Requirements
PHP >= 7.0
Installation
Package can be installed using composer composer require cocoders/event-store
Usage
Library provides bunch of interfaces and about 5 concrete classes for handling domain events.
What you need to do in order to setup this event store with your project? Follow those 5 steps.
-
Step 1 - define you aggregate In your aggregate you need implement
Cocoders\EventStore\AggregateRoot
interface (you can useCocoders\EventStore\AggregateRootBehavior
trait if tou want). Example: Example Domain Invoice Aggregate -
Step 2 - define own events and use it in aggregate You should define new event classes and use those events in you aggregate
- Example of using events in Invoice
- Example of event class
-
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 - Step 4 - do some operation on aggregate and add fresh events from Aggregate to event store, and commit event store.
Examples:
- Execute logic on aggregate
- Apply using repository pattern
- Commit using command bus middleware
-
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:
- More examples: You can see whole working example setup in IntegrationWithExampleDomainTest
Development and tests
To develop this lib we are using docker and docker-compose. After installation of those you should run:
Then on docker console run: