PHPackages                             rsousa/flows - 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. rsousa/flows

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

rsousa/flows
============

A lightweight, BPMN-inspired workflow engine for PHP 8.1+

v2.9(2mo ago)071MITPHPPHP &gt;=8.1CI passing

Since Feb 22Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/sousarmb/flows)[ Packagist](https://packagist.org/packages/rsousa/flows)[ RSS](/packages/rsousa-flows/feed)WikiDiscussions main Synced 1mo ago

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

Flows
=====

[](#flows)

A lightweight, BPMN-inspired workflow engine for PHP 8.1+.

Flows lets you build resumable, observable workflows with branching logic, savepoints, and undo - all in plain PHP with few external dependencies.

Use for multi-step forms, sagas, wizards, or any long-running business process.

Requirements
------------

[](#requirements)

- PHP 8.1+

Current features:
=================

[](#current-features)

Flows PHP library can be used as a standalone tool to create your own application or in conjunction with your favorite PHP framework as an embeddable library.

- [Abstract/Concrete object factory](#abstract-and-concrete-object-factory)
- [Configurable](#configurable)
- [Event handling](#event-handling)
- [Facades](#facades)
- [Gate, process and task observability](#gate-process-and-task-observability)
- [Process offloading](#process-offloading)
- [React to external events](#react-to-external-events)
- [Save/Undo process states](#saveundo-process-state)
- [Service container](#service-container)

Planned features:
-----------------

[](#planned-features)

- [Process serialization (planned, WIP)](#process-serialization-wip)

Live Demo
---------

[](#live-demo)

See it in action right now:

Clone and run the demos, they use the current [main](https://github.com/sousarmb/flows/blob/main/README.md) version of Flows.

### Quick Start (5 minutes)

[](#quick-start-5-minutes)

```
git clone https://github.com/sousarmb/flows-example-app.git flows-demo
cd flows-demo
docker-compose up -d
docker exec -ti flows-example-app bash
```

Install dependencies with:

```
composer install
```

Run the process branching with XOR gate demo with:

```
php App/demo-branch-xor-gate.php
```

Try the other demos in the [`App`](https://github.com/sousarmb/flows-example-app/tree/main/App) directory.

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

[](#installation)

This package can be installed as a [Composer](https://getcomposer.org/) dependency with:

```
composer require rsousa/flows
```

After installation use the `flows help` command to get help on how to create the components needed to create your workflows:

```
vendor/bin/flows help
```

Then start with:

```
vendor/bin/flows create:scaffold
```

To create the necessary directories and files to write your application.

How it works
============

[](#how-it-works)

The building blocks of flows are tasks, processes and gates.

Application code is written inside tasks. Tasks receive input from the previous task and return output to be used as the next task input or process start.

Tasks are executed sequencially in a process.

Processes group tasks and act as pipelines, controlling task input and output, handing over control to the application kernel when it's time to branch to another process.

Branching is controlled by the application kernel.

When the developer needs to branch to another process it places a gate in the process.

Gates have access to task output and the developer may use it to write logic to select where to branch next, creating the workflow.

Branch exclusively or in parallel. Parallel branches always return to the process where they branched. Exclusive branches do not, they may go a different flow.

Once the workflow ends (no more branching occurs), process output is returned to the calling code (when running as embeddable library) or the application exits.

Workflow Example
----------------

[](#workflow-example)

### XOR Gate

[](#xor-gate)

 ```
flowchart TB
    n1["Start"] --> A["Process A"]
    A --> B["Process B"]
    B --> XOR{"XORGate"}
    XOR -- Chosen? --> C["Process C"] & D["Process D"] & E["Process E"]
    C --> n2["Stop"]
    D --> n2["Stop"]
    E --> F["Process F"]
    F --> n2["Stop"]

    n1@{ shape: start}
    n2@{ shape: stop}
```

      Loading ### And Gate

[](#and-gate)

 ```
flowchart TB
    n1["Start"] --> A["Process A"]
    A --> B["Process B"]
    B --> AND{"AndGate"}
    AND -- Run in parallel --> C["Process C"] & D["Process D"] & E["Process E"]
    C --> H["Process H"]
    D --> H
    E --> H
    H --> n2["Stop"]
    n1@{ shape: start}
    n2@{ shape: stop}
```

      Loading First Project
=============

[](#first-project)

1. Plan your tasks and group them into processes
2. Create task class(es) (as many as needed) with:

```
vendor/bin/flows create:task name=[task-class-name]
```

3. Create input/output class(es) for your tasks with:

```
vendor/bin/flows create:io name=[io-class-name]
```

3. Create process class(es) to group the tasks with:

```
vendor/bin/flows create:process name=[process-class-name]
```

4. Create gate class(es) to branch processes with:

```
vendor/bin/flows create:gate name=[gate-class-name]
```

5. Create a PHP script in the `App` directory:

```
touch App/[workflow-class-name].php
```

6. Edit the script to create the workflow:

```
