PHPackages                             ufo-tech/event-sourcing - 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. ufo-tech/event-sourcing

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

ufo-tech/event-sourcing
=======================

A lightweight event sourcing library with aggregates, event store and projections for modern PHP applications.

1.4.2(4mo ago)3685↓83.7%MITPHPPHP &gt;=8.4

Since Jun 11Pushed 4mo agoCompare

[ Source](https://github.com/UFO-Tech/event-sourcing)[ Packagist](https://packagist.org/packages/ufo-tech/event-sourcing)[ Docs](https://docs.ufo-tech.space/bin/view/docs/EventSourcing/?language=en)[ RSS](/packages/ufo-tech-event-sourcing/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (2)Versions (10)Used By (0)

UFO Event Sourcing
==================

[](#ufo-event-sourcing)

**A lightweight and modern Event Sourcing library for PHP 8.3+**

---

🚀 Features
----------

[](#-features)

- Stores domain events instead of the current state
- Rebuilds aggregate state through event replay
- Supports projections for building read models
- Provides interfaces for custom event stores and dispatchers

---

📖 Core Concepts
---------------

[](#-core-concepts)

- **Resolver** — module for generating differences between old and new state.
- **Restorer** — module for rebuilding an object from changes.
- **Merger** — service for step-by-step application of changes to an object.
- **ContextDTO** — DTO for passing context during change analysis (path, collection type, attributes).
- **Attributes** — PHP 8.3 attributes for controlling change detection behavior.

---

🛠 Installation
--------------

[](#-installation)

```
composer require ufo-tech/event-sourcing
```

---

📦 Components
------------

[](#-components)

### Resolver

[](#resolver)

ClassDescription`MainResolver`Delegates change detection to appropriate resolver`ObjectResolver`Handles objects via Reflection API`CollectionResolver`Supports associative arrays`ArrayResolver`Handles indexed arrays`ScalarResolver`Compares scalar values### Restorer &amp; Merger

[](#restorer--merger)

ClassDescription`Merger`Merges changes into the base state`ObjectRestorer`Rebuilds an object from a collection of changes via `DTOTransformer``ObjectDefinition`Defines the object type to restore from change history### Interfaces

[](#interfaces)

InterfacePurpose`ResolverInterface`Detects changes between states`MergerInterface`Merges changes into a state`RestorerInterface`Restores an object from change history`MainResolverInterface`Encapsulates multiple resolvers`MainResolverFactoryInterface`Factory for creating the main resolver---

🟠 Attributes
------------

[](#-attributes)

AttributePurpose`#[ChangeIgnore]`Ignores a field during change detection`#[AsCollection]`Marks a field as a key-based collection---

🟢 Contexts
----------

[](#-contexts)

`ContextDTO` allows passing additional metadata during resolving:

- Current path (`path`)
- Type (collection/array/scalar)
- Special delete placeholder (`__DELETED__`)
- Supports nested paths for objects and collections

### ContextDTO Rules

[](#contextdto-rules)

- `ContextDTO::create()` creates a base context with root path `root`.
- `forPath(string $param)` adds a path segment (e.g., `root.products`).
- `makeAssocByPath(string $path)` marks a path as associative (e.g., `products`, `root.products.*`).
- Supports pattern paths with `$` that converts to `*` for nested collections.
- Delete placeholder can be customized via `ContextDTO::create(deletePlaceholder: '__DELETED__')`.

#### Examples:

[](#examples)

```
use Ufo\EventSourcing\Resolver\ContextDTO;

// Single path
$context = new ContextDTO(assocPaths: ['products']);
$context = new ContextDTO(assocPaths: 'products');

// Multiple paths
$context = new ContextDTO(assocPaths: ['products', 'items.subitems']);

// Custom delete placeholder
$context = new ContextDTO(deletePlaceholder: '__DELETED__', assocPaths: ['products']);
```

#### Using patterns:

[](#using-patterns)

```
// All subitems inside any items are treated as collections
$context = ContextDTO::create()
    ->makeAssocByPath('items.$.subitems');

// products.*.discounts.*.details are treated as associative
$context = ContextDTO::create()
    ->makeAssocByPath('products.$.discounts.$.details');

// Root-level collection
$context = ContextDTO::create(assocPaths: ['']);
```

📝 Note: `$` automatically converts to `*` for wildcard path matching.

---

📝 Usage Examples
----------------

[](#-usage-examples)

### Detecting Changes

[](#detecting-changes)

```
$mainResolver = (new DefaultResolverFactory())->create();
$diff = $mainResolver->resolve($oldObject, $newObject);
```

### Using context for associative collection

[](#using-context-for-associative-collection)

```
$context = ContextDTO::create()->makeAssocByPath('products');
$diff = $mainResolver->resolve($old, $new, $context);
```

### Restoring an object from change history

[](#restoring-an-object-from-change-history)

```
$restorer = new ObjectRestorer(new Merger());
$restored = $restorer->restore(
    (new ObjectDefinition(MyDto::class))
        ->addChanges($firstChange)
        ->addChanges($secondChange)
);
```

---

📚 Use Cases
-----------

[](#-use-cases)

- Event Sourcing and CQRS architectures
- Domain-Driven Design (DDD) based projects
- Service-oriented systems with event-based persistence

---

📖 Documentation
---------------

[](#-documentation)

Full documentation available at [docs.ufo-tech.space](https://docs.ufo-tech.space/bin/view/docs/EventSourcing/?language=en)

---

📜 License
---------

[](#-license)

MIT © [UFO Tech](https://ufo-tech.space)

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance77

Regular maintenance activity

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Recently: every ~53 days

Total

8

Last Release

127d ago

PHP version history (2 changes)1.0.0PHP &gt;=8.3

1.2.0PHP &gt;=8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/35559645?v=4)[Valchik](/maintainers/Valchik)[@valchik](https://github.com/valchik)

![](https://www.gravatar.com/avatar/87aea0bcf81c64ced7c3a14a1746d603ec6e8acfba62ef85746df40e8c376e7f?d=identicon)[Alex Maistrenko](/maintainers/Alex%20Maistrenko)

---

Top Contributors

[![valiknik225](https://avatars.githubusercontent.com/u/137418080?v=4)](https://github.com/valiknik225 "valiknik225 (8 commits)")

---

Tags

phpdddevent sourcingevent storecqrsufo-techdomain-eventsaggregatesprojections

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ufo-tech-event-sourcing/health.svg)

```
[![Health](https://phpackages.com/badges/ufo-tech-event-sourcing/health.svg)](https://phpackages.com/packages/ufo-tech-event-sourcing)
```

###  Alternatives

[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)[patchlevel/event-sourcing

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

207362.9k13](/packages/patchlevel-event-sourcing)[dykyi-roman/awesome-claude-code

Claude Code extension for PHP: audits (architecture, DDD, security, performance, PSR, design patterns, Docker, CI/CD, tests, docs), 3-level code review, automated bug fix, generators (DDD, CQRS, GoF patterns, PSR, tests, documentation, Docker, CI/CD), code explanation, refactoring. 26 commands, 62 agents, 259 skills.

851.2k](/packages/dykyi-roman-awesome-claude-code)[prooph/snapshotter

snapshot tool for prooph event-store

19172.8k3](/packages/prooph-snapshotter)[pauci/cqrs

CQRS library

1725.2k3](/packages/pauci-cqrs)[honeybee/honeybee

Library for implementing CQRS driven, event-sourced and distributed architectures.

222.1k4](/packages/honeybee-honeybee)

PHPackages © 2026

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