PHPackages                             solidframe/saga - 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. [Queues &amp; Workers](/categories/queues)
4. /
5. solidframe/saga

ActiveLibrary[Queues &amp; Workers](/categories/queues)

solidframe/saga
===============

Saga / Process Manager building blocks: saga lifecycle, compensation, correlation, store for SolidFrame

v0.1.0(3mo ago)03MITPHP ^8.2

Since Apr 11Compare

[ Source](https://github.com/solidframe/saga)[ Packagist](https://packagist.org/packages/solidframe/saga)[ RSS](/packages/solidframe-saga/feed)WikiDiscussions Synced 3w ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

SolidFrame Saga
===============

[](#solidframe-saga)

Saga / Process Manager building blocks: saga lifecycle, compensation, correlation, and persistence.

Orchestrate multi-step business processes with automatic compensation on failure.

Installation
------------

[](#installation)

```
composer require solidframe/saga
```

Quick Start
-----------

[](#quick-start)

### Define a Saga

[](#define-a-saga)

```
use SolidFrame\Saga\Saga\AbstractSaga;

final class PlaceOrderSaga extends AbstractSaga
{
    public function handleOrderPlaced(OrderPlaced $event): void
    {
        // Correlate saga to order
        $this->associateWith('orderId', $event->orderId);

        // Step 1: Reserve inventory
        $this->reserveInventory($event);

        // Register compensation in case of failure
        $this->addCompensation(fn () => $this->releaseInventory($event->orderId));
    }

    public function handlePaymentCompleted(PaymentCompleted $event): void
    {
        // Step 2: Confirm order
        $this->confirmOrder($event->orderId);
        $this->complete();
    }

    public function handlePaymentFailed(PaymentFailed $event): void
    {
        // Triggers all compensations in reverse order
        $this->fail();
    }

    // ...
}
```

### Saga Lifecycle

[](#saga-lifecycle)

```
$saga = new PlaceOrderSaga();

$saga->status();      // SagaStatus::InProgress
$saga->isCompleted(); // false
$saga->isFailed();    // false

// After complete()
$saga->status();      // SagaStatus::Completed
$saga->isCompleted(); // true

// After fail() — compensations execute automatically
$saga->status();      // SagaStatus::Failed
$saga->isFailed();    // true
```

Associations (Correlation)
--------------------------

[](#associations-correlation)

Sagas are correlated to external entities via key-value associations:

```
$saga->associateWith('orderId', 'order-123');
$saga->associateWith('customerId', 'customer-456');

$saga->associations();
// [Association(key: 'orderId', value: 'order-123'), ...]

$saga->removeAssociation('customerId');
```

Find sagas by association:

```
$saga = $sagaStore->findByAssociation(
    PlaceOrderSaga::class,
    new Association('orderId', 'order-123'),
);
```

Compensation
------------

[](#compensation)

Compensations are registered during saga execution and run in **reverse order** on failure:

```
// Step 1
$this->reserveInventory($orderId);
$this->addCompensation(fn () => $this->releaseInventory($orderId));

// Step 2
$this->chargePayment($orderId);
$this->addCompensation(fn () => $this->refundPayment($orderId));

// On failure: refundPayment() runs first, then releaseInventory()
$this->fail();
```

You can also trigger compensation manually:

```
$saga->compensate();
```

Persistence
-----------

[](#persistence)

### Saga Store

[](#saga-store)

```
use SolidFrame\Saga\Store\SagaStoreInterface;

// Save
$sagaStore->save($saga);

// Find by ID
$saga = $sagaStore->find('saga-id');

// Find by association
$saga = $sagaStore->findByAssociation(
    PlaceOrderSaga::class,
    new Association('orderId', 'order-123'),
);

// Delete
$sagaStore->delete('saga-id');
```

### In-Memory Store

[](#in-memory-store)

For testing and prototyping:

```
use SolidFrame\Saga\Store\InMemorySagaStore;

$store = new InMemorySagaStore();
```

Saga Status
-----------

[](#saga-status)

```
use SolidFrame\Saga\State\SagaStatus;

SagaStatus::InProgress; // 'in_progress' — saga is executing
SagaStatus::Completed;  // 'completed'   — saga finished successfully
SagaStatus::Failed;     // 'failed'      — saga failed, compensations applied
```

API Reference
-------------

[](#api-reference)

Class / InterfacePurpose`SagaInterface`Contract for saga objects`AbstractSaga`Base saga with lifecycle and compensation`SagaStoreInterface`Persistence contract`InMemorySagaStore`In-memory store for testing`Association`Key-value correlation object`SagaStatus`Enum: InProgress, Completed, Failed`SagaNotFoundException`Saga not found in storeRelated Packages
----------------

[](#related-packages)

- [solidframe/core](../core) — Base exception interface
- [solidframe/modular](../modular) — Sagas often orchestrate cross-module processes
- [solidframe/cqrs](../cqrs) — Saga handlers dispatch commands
- [solidframe/laravel](../laravel) — Database SagaStore, `make:saga`, `solidframe:saga:status`
- [solidframe/symfony](../symfony) — DBAL SagaStore, same generators

Contributing
------------

[](#contributing)

This repository is a read-only split of the [solidframe/solidframe](https://github.com/solidframe/solidframe) monorepo, auto-synced on every push to `main`. Issues, pull requests, and discussions belong in the monorepo.

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance80

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

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

Unknown

Total

1

Last Release

104d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/97de2a466719393a21a8ce5caef247a1afb8aec5a8974248da0583f4197765b2?d=identicon)[abdulkadir-posul](/maintainers/abdulkadir-posul)

### Embed Badge

![Health badge](/badges/solidframe-saga/health.svg)

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

###  Alternatives

[league/geotools

Geo-related tools PHP 7.3+ library

1.4k5.6M31](/packages/league-geotools)[illuminate/bus

The Illuminate Bus package.

6046.3M586](/packages/illuminate-bus)[brave-sir-robin/amqphp

AMQP 0.9.1 Protocol Implementation in pure PHP

7932.8k](/packages/brave-sir-robin-amqphp)[belvg/module-sqs

N/A

1544.6k](/packages/belvg-module-sqs)[mayconbordin/l5-stomp-queue

Stomp Queue Driver for Laravel 5

121.1k](/packages/mayconbordin-l5-stomp-queue)

PHPackages © 2026

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