PHPackages                             neos/eventstore - 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. [Database &amp; ORM](/categories/database)
4. /
5. neos/eventstore

ActiveLibrary[Database &amp; ORM](/categories/database)

neos/eventstore
===============

Store for Event-Sourced applications

2.0.0(3w ago)178.2k↑73.4%3[1 issues](https://github.com/neos/eventstore/issues)5MITPHPPHP ^8.2CI passing

Since Nov 7Pushed 3w ago6 watchersCompare

[ Source](https://github.com/neos/eventstore)[ Packagist](https://packagist.org/packages/neos/eventstore)[ Fund](https://www.neos.io/community/participate/supporting-neos.html)[ RSS](/packages/neos-eventstore/feed)WikiDiscussions 2.0 Synced 2d ago

READMEChangelog (5)Dependencies (13)Versions (13)Used By (5)

General purpose event store
===========================

[](#general-purpose-event-store)

This package provides interfaces and helpers to create Event-Sourced systems with PHP

Scope
-----

[](#scope)

In contrast to [Neos.EventSourcing](https://github.com/neos/Neos.EventSourcing) this package provides merely the low-level building blocks, has just a couple of dependencies and is less opinionated.

Note

This package mostly contains interfaces and implementations of Data Transfer Objects. To actually persist events, a corresponding adapter package is required, for example [neos/eventstore-doctrineadapter](https://github.com/neos/eventstore-doctrineadapter)

Usage
-----

[](#usage)

Install via [composer](https://getcomposer.org):

```
composer require neos/eventstore
```

### Appending events

[](#appending-events)

#### Commit a single event to the event store

[](#commit-a-single-event-to-the-event-store)

```
$eventStore->commit(
    streamName: StreamName::fromString('some-stream'),
    events: new Event(EventId::create(), EventType::fromString('SomeEventType'), EventData::fromString('{"foo": "bar"}')),
    expectedVersion: ExpectedVersion::ANY(),
);
```

#### Commit multiple events at once

[](#commit-multiple-events-at-once)

```
$correlationId = Uuid::uuid4()->toString();
$eventStore->commit(
    streamName: StreamName::fromString('some-stream'),
    events: Events::fromArray([
        new Event(EventId::create(), EventType::fromString('SomeEventType'), EventData::fromString('foo'), correlationId: $correlationId),
        new Event(EventId::create(), EventType::fromString('SomeOtherType'), EventData::fromString('bar'), correlationId: $correlationId])),
    ]),
    expectedVersion: ExpectedVersion::ANY(),
);
```

> **Note**Multiple events can only ever be appended to the same stream at once

#### Expected version

[](#expected-version)

Event-sourced systems are eventual consistent. This basically means that the models, that are used to base decisions on, might be out of date. The `ExpectedVersion` can be used to make sure, that no new events where appended to the stream since the model was reconstituted from the events. That mechanism can be used to implement event-sourced aggregates.

##### ExpectedVersion::ANY

[](#expectedversionany)

`ExpectedVersion::ANY()` (as used in the examples above) skips the version check entirely and should only be used if no hard constraints are required.

##### ExpectedVersion::NO\_STREAM

[](#expectedversionno_stream)

`ExpectedVersion::NO_STREAM()` can be used to make sure that a given stream does not yet exist. This is useful for events that represent the creation of an entity:

```
$eventStore->commit(
    streamName: StreamName::fromString('customer-' . $customerId->value),
    events: new Event(EventId::create(), EventType::fromString('CustomerHasSignedUp'), EventData::fromString($customerData->toJson())),
    expectedVersion: ExpectedVersion::NO_STREAM(),
);
```

If the same code was executed again (with the same `$customId`) it would fail

##### ExpectedVersion::STREAM\_EXISTS

[](#expectedversionstream_exists)

`ExpectedVersion::STREAM_EXISTS()` is basically the opposite of `NO_STREAM`: It fails if no events have been committed to the stream before

### Reading events

[](#reading-events)

#### Iterate over all events of a stream

[](#iterate-over-all-events-of-a-stream)

To load all events and output their sequence number and type:

```
foreach ($eventStore->load(StreamName::fromString('some-stream')) as $eventEnvelope) {
    echo $eventEnvelope->sequenceNumber->value . ': ' . $eventEnvelope->event->type->value . PHP_EOL;
}
```

#### Filter event stream

[](#filter-event-stream)

`EventStoreInterface::load()` expects a second, optional, argument that allows to filter the event stream. This can be used to only load events of a certain type:

```
$stream = $eventStore->load(
    streamName: StreamName::fromString('some-stream'),
    filter: EventStreamFilter::create(eventTypes: EventTypes::create(EventType::fromString('SomeEventType')))
);
```

Note

Filtering events based on their type is a low-level optimization that is usually not required and should only be applied if needed

#### Navigate the event stream

[](#navigate-the-event-stream)

The resulting `EventStreamInterface` of the `EventStoreInterface::load()` call is a lazy representation of the stream. Depending on the actual implementation the events are only loaded whenever they are *accessed*.

The `EventStreamInterface` provides four methods to affect ordering and window of the events to load:

- `withMinimumSequenceNumber()` to specify the lowest `SequenceNumber` that should be included in the stream
- `withMaximumSequenceNumber()` to specify the highest `SequenceNumber` that should be included in the stream
- `limit()` to specify the maximum number of events to load in total
- `backwards()` to load events in *descending* order.

Usually the `withMinimumSequenceNumber()` is used to only load events that have not been processed yet by an event handler, but sometimes it can be useful to allow for arbitrary event stream navigation.

The following example will read at most 10 events with sequence number between 500 and 1000 in descending order:

```
$stream = $eventStore->load(StreamName::fromString('some-stream'))
    ->withMinimumSequenceNumber(SequenceNumber::fromInteger(500))
    ->withMaximumSequenceNumber(SequenceNumber::fromInteger(1000))
    ->limit(10)
    ->backwards();
```

### Deleting events

[](#deleting-events)

Events form the unique source of truth in a system and thus should never be deleted. In theory. In practice, it can be useful to be able to remove streams that are not in use any longer.

The following example deletes all events from "some-stream":

```
$eventStore->deleteStream(StreamName::fromString('some-stream'));
```

Warning

For obvious reasons, this method should only be used with great care. Mostly there are better ways to solve issues that seem to require deletion of events. Also note, that some Event store implementations might not support this feature

### More examples

[](#more-examples)

@see [tests](tests) for more examples.

Contribution
------------

[](#contribution)

Contributions in the form of [issues](https://github.com/neos/eventstore/issues), [pull requests](https://github.com/neos/eventstore/pulls) or [discussions](https://github.com/neos/eventstore/discussions) are highly appreciated

License
-------

[](#license)

See [LICENSE](./LICENSE)

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance75

Regular maintenance activity

Popularity35

Limited adoption so far

Community25

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~157 days

Recently: every ~202 days

Total

7

Last Release

23d ago

Major Versions

1.0.x-dev → 2.0.02026-06-10

PHP version history (2 changes)1.0.0-beta1PHP ^8.1

2.0.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/11575267?v=4)[Neos](/maintainers/neos)[@neos](https://github.com/neos)

---

Top Contributors

[![mhsdesign](https://avatars.githubusercontent.com/u/85400359?v=4)](https://github.com/mhsdesign "mhsdesign (57 commits)")[![bwaidelich](https://avatars.githubusercontent.com/u/307571?v=4)](https://github.com/bwaidelich "bwaidelich (52 commits)")[![skurfuerst](https://avatars.githubusercontent.com/u/190777?v=4)](https://github.com/skurfuerst "skurfuerst (6 commits)")[![kitsunet](https://avatars.githubusercontent.com/u/324408?v=4)](https://github.com/kitsunet "kitsunet (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/neos-eventstore/health.svg)

```
[![Health](https://phpackages.com/badges/neos-eventstore/health.svg)](https://phpackages.com/packages/neos-eventstore)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.9M738](/packages/sylius-sylius)[bavix/laravel-wallet

It's easy to work with a virtual wallet.

1.3k1.3M19](/packages/bavix-laravel-wallet)[patchlevel/event-sourcing

A lightweight but also all-inclusive event sourcing library with a focus on developer experience

207362.9k13](/packages/patchlevel-event-sourcing)[neos/neos-development-collection

Neos packages in a joined repository for pull requests.

267103.9k1](/packages/neos-neos-development-collection)[ssch/typo3-rector

Instant fixes for your TYPO3 PHP code by using Rector.

2603.2M436](/packages/ssch-typo3-rector)[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

564576.7k53](/packages/ecotone-ecotone)

PHPackages © 2026

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