PHPackages                             jardissupport/workflow - 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. jardissupport/workflow

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

jardissupport/workflow
======================

Directed workflow engine with status-based transitions, automatic data accumulation, and builder API

v1.0.7(yesterday)014MITPHPPHP &gt;=8.2CI passing

Since Jun 2Pushed 2w agoCompare

[ Source](https://github.com/jardisSupport/workflow)[ Packagist](https://packagist.org/packages/jardissupport/workflow)[ Docs](https://jardis.io)[ RSS](/packages/jardissupport-workflow/feed)WikiDiscussions main Synced today

READMEChangelog (6)Dependencies (20)Versions (14)Used By (0)

Jardis Workflow
===============

[](#jardis-workflow)

[![Build Status](https://github.com/jardisSupport/workflow/actions/workflows/ci.yml/badge.svg)](https://github.com/jardisSupport/workflow/actions/workflows/ci.yml/badge.svg)[![License: MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](LICENSE.md)[![PHP Version](https://camo.githubusercontent.com/a68b290dcc313d698dc138a1111aa83eee2f143605449d7e8b5416ea6f88558f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344382e322d3737374242342e737667)](https://www.php.net/)[![PHPStan Level](https://camo.githubusercontent.com/c51bda247654363d3e30bc352674dd761a9557803a14af0226eb411d6dc0006b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c253230382d627269676874677265656e2e737667)](phpstan.neon)[![PSR-12](https://camo.githubusercontent.com/34b10db0caa29bacd49bda5c437a8de95385f036f3230b31fa605326e18da22c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f64652532305374796c652d5053522d2d31322d626c75652e737667)](phpcs.xml)[![Coverage](https://camo.githubusercontent.com/521d3bbc971b35cd8f60001db0d331b8169c67dffdac7049914452ef56deda9d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f7665726167652d39392e32322532352d627269676874677265656e2e737667)](https://github.com/jardisSupport/workflow)

> Part of **[Jardis](https://jardis.io)** — the Domain-Driven Design platform for PHP. You model your domain; Jardis generates the production-ready hexagonal code (DTOs, Command/Query handlers, repositories, persistence). This package is part of the open-source foundation that generated code runs on.

Directed workflow engine for multi-step process orchestration in PHP. Define handler graphs with named transitions, propagate every step's result through a typed context, and wire it all up with a fluent API. Each handler returns a `WorkflowResult` whose status — one of seven `ON_*` constants — picks the next step.

---

Features
--------

[](#features)

- **Directed Handler Graph** — connect handlers as nodes with explicit per-status transitions
- **Seven Named Transitions** — `onSuccess`, `onFail`, `onTimeout`, `onSkip`, `onCancel`, `onEvent`, `onExit` (loop/block termination)
- **R5 Routing-Safety** — when a transition target is not a registered node, the engine returns control to the caller (no dispatch, no exception)
- **Typed Execution Context** — `WorkflowContext` carries every handler invocation as an entry in an ordered execution log; `getPrevious()` exposes the immediate predecessor's result without the handler needing to know who that was
- **Lossless History** — re-invocations of the same handler (retry loops, cross-branch revisits) append a new entry instead of overwriting; `getAll(Foo::class)` returns every invocation, `getLatest(Foo::class)` the most recent
- **Fluent Builder API** — `WorkflowBuilder` + `WorkflowNodeBuilder` wire the graph without configuration arrays
- **Handler Factory** — inject a closure to resolve handlers from a DI container
- **WorkflowResult** — typed value object with named status constants; no ambiguous truthy/falsy returns

---

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

[](#installation)

```
composer require jardissupport/workflow
```

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

[](#quick-start)

```
use JardisSupport\Workflow\Builder\WorkflowBuilder;
use JardisSupport\Workflow\Workflow;
use JardisSupport\Workflow\WorkflowResult;

// Build a two-step graph
$config = (new WorkflowBuilder())
    ->node(ValidateOrderHandler::class)
        ->onSuccess(ChargePaymentHandler::class)
        ->onFail(RejectOrderHandler::class)
    ->node(ChargePaymentHandler::class)
        ->onSuccess(ConfirmOrderHandler::class)
    ->build();

// Workflow is stateless and single-shot. Per-run input is passed as $data and forwarded
// to the handler factory — handlers themselves are invoked with the WorkflowContext only.
$workflow = new Workflow(
    handlerFactory: fn(string $cls, mixed $data): object => new $cls($data),
);
$context  = $workflow($config, $order);

// Inspect the final result and the full chain
$lastResult   = $context->getPrevious();                          // WorkflowResult of last executed handler
$chargeResult = $context->getLatest(ChargePaymentHandler::class); // most recent invocation of that handler
$allCharges   = $context->getAll(ChargePaymentHandler::class);    // every invocation in execution order
$executed     = count($context->getChain());                      // total number of handler invocations
```

Advanced Usage
--------------

[](#advanced-usage)

```
use JardisSupport\Contract\Workflow\WorkflowContextInterface;
use JardisSupport\Workflow\Builder\WorkflowBuilder;
use JardisSupport\Workflow\Workflow;
use JardisSupport\Workflow\WorkflowResult;

// Handler using named transitions (retry loop). All handlers share the same signature:
// __invoke(WorkflowContextInterface): WorkflowResultInterface — per-run input is wired in
// by the handler factory (e.g. injected via constructor or set as the BoundedContext payload).
class ChargePaymentHandler
{
    public function __construct(private readonly Order $order) {}

    public function __invoke(WorkflowContextInterface $context): WorkflowResult
    {
        // Count prior invocations from the chain — every retry has a fresh entry
        $attempt = count($context->getAll(self::class)) + 1;

        $gatewayResult = $this->gateway->charge($this->order->total);

        if ($gatewayResult->isTemporaryFailure()) {
            // Service-side timeout translated into a domain transition — loops back via ON_TIMEOUT
            return new WorkflowResult(WorkflowResult::ON_TIMEOUT, ['attempt' => $attempt]);
        }

        if (!$gatewayResult->isSuccess()) {
            return new WorkflowResult(WorkflowResult::ON_FAIL, ['error' => $gatewayResult->message]);
        }

        return new WorkflowResult(WorkflowResult::ON_SUCCESS, ['chargeId' => $gatewayResult->id]);
    }
}

// Wire the timeout retry back to the same handler
$config = (new WorkflowBuilder())
    ->node(ChargePaymentHandler::class)
        ->onSuccess(FulfillOrderHandler::class)
        ->onFail(NotifyFailureHandler::class)
        ->onTimeout(ChargePaymentHandler::class)   // self-loop for retry-like behaviour
    ->build();

// Inject handlers from a DI container; the factory receives both the FQCN and the
// per-run $data passed to $workflow($config, $data).
$workflow = new Workflow(
    fn(string $class, mixed $data): object => $container->get($class)->withOrder($data),
);

$context = $workflow($config, $order);

// Inspect the chain — flat ordered execution log; every entry is a stamped WorkflowResult
foreach ($context->getChain() as $result) {
    echo "{$result->getHandlerFqcn()}: {$result->getStatus()}\n";
}
```

Documentation
-------------

[](#documentation)

Full documentation, guides, and API reference:

**[docs.jardis.io/en/support/workflow](https://docs.jardis.io/en/support/workflow)**

License
-------

[](#license)

This package is licensed under the [MIT License](LICENSE.md).

---

**[Jardis](https://jardis.io)** · [Documentation](https://docs.jardis.io) · [Headgent](https://headgent.com)

AI-Assisted Development
-----------------------

[](#ai-assisted-development)

This package ships with a skill for Claude Code, Cursor, Continue, and Aider. Install it in your consuming project:

```
composer require --dev jardis/dev-skills
```

More details:

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance98

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity53

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

Recently: every ~5 days

Total

9

Last Release

1d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e07a1b668e9e01ee6d1b85de7b3be1c2513f68aae9494b2011d1592104d5daa0?d=identicon)[jardis](/maintainers/jardis)

---

Top Contributors

[![Headgent](https://avatars.githubusercontent.com/u/245725954?v=4)](https://github.com/Headgent "Headgent (9 commits)")

---

Tags

domain-driven-designjardisorchestrationphpprocess-orchestrationworkflowphpworkflowDomain Driven Designstate-machineorchestrationstepsHeadgentjardistransitionsprocess-orchestration

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jardissupport-workflow/health.svg)

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

PHPackages © 2026

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