PHPackages                             cocoders/event-store - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. cocoders/event-store

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

cocoders/event-store
====================

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

0.1.1(10y ago)14915MITPHPPHP ^7.0

Since Mar 3Pushed 10y ago3 watchersCompare

[ Source](https://github.com/cocoders/event-store)[ Packagist](https://packagist.org/packages/cocoders/event-store)[ RSS](/packages/cocoders-event-store/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (2)Dependencies (4)Versions (3)Used By (0)

Quite basic and simple Event Store abstraction layer
====================================================

[](#quite-basic-and-simple-event-store-abstraction-layer)

[![Travis build](https://camo.githubusercontent.com/380caa7f1627145671bf4f22c32376e984b2fed281a37ed7e6e77e54c320051c/68747470733a2f2f6170692e7472617669732d63692e6f72672f636f636f646572732f6576656e742d73746f72652e737667)](https://travis-ci.org/cocoders/event-store)

Event store layer to help us - [Cocoders](http://cocoders.com) to implement event sourcing in our projects. It is quite simple (or event stupid) abstraction layer (yunno [KISS](https://en.wikipedia.org/wiki/KISS_principle))

Requirements
============

[](#requirements)

**PHP &gt;= 7.0**

Installation
============

[](#installation)

Package can be installed using composer `composer require cocoders/event-store`Usage
====================================================================================

[](#package-can-be-installed-using-composer-composer-require-cocodersevent-storeusage)

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.

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](tests/ExampleDomain/Invoice.php)
2. 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](tests/ExampleDomain/Invoice.php)
    - [Example of event class](tests/ExampleDomain/Invoice/Events/InvoiceAdded.php)
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](tests/ExampleDomain/Infastracture/File/EventStore.php)
4. Step 4 - do some operation on aggregate and add fresh events from Aggregate to event store, and commit event store.

Examples:

```
    $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();
```

- [Execute logic on aggregate](tests/ExampleDomain/UseCase/IssueInvoice.php)
- [Apply using repository pattern](tests/ExampleDomain/EventStore/Invoices.php)
- [Commit using command bus middleware](tests/ExampleDomain/CommandBus/EventStoreMiddleware.php)

5. 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
```

- More examples: You can see whole working example setup in [IntegrationWithExampleDomainTest](tests/Tests/IntegrationWithExampleDomainTest.php)

Development and tests
=====================

[](#development-and-tests)

To develop this lib we are using [docker](http://docker.io) and [docker-compose](https://docs.docker.com/compose/overview/). After installation of those you should run:

```
    docker-compose up
    docker-compose run eventstore bash
```

Then on docker console run:

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

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~6 days

Total

2

Last Release

3756d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/209405?v=4)[Leszek Prabucki](/maintainers/l3l0)[@l3l0](https://github.com/l3l0)

---

Top Contributors

[![l3l0](https://avatars.githubusercontent.com/u/209405?v=4)](https://github.com/l3l0 "l3l0 (16 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cocoders-event-store/health.svg)

```
[![Health](https://phpackages.com/badges/cocoders-event-store/health.svg)](https://phpackages.com/packages/cocoders-event-store)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
