PHPackages                             stateflow/engine - 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. stateflow/engine

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

stateflow/engine
================

A clean, auditable state machine for PHP 8.2+

v1.0.1(3mo ago)01[8 issues](https://github.com/EnmanuelVarelaPividori/stateflow-engine/issues)MITPHPPHP ^8.2CI passing

Since Jan 27Pushed 3mo agoCompare

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

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

StateFlow Engine
================

[](#stateflow-engine)

A clean, auditable state machine for PHP 8.2+

[![Latest Version](https://camo.githubusercontent.com/764273bb37bd68ad46bf1f5347d89d430f5f2718533d515e4ea4189a1348d69e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7374617465666c6f772f656e67696e652e737667)](https://packagist.org/packages/stateflow/engine)[![PHP Version](https://camo.githubusercontent.com/f1ddaa57d81396a064de45413ee9a4c94f24c50c32645bd6cdf22747201b97ea/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7374617465666c6f772f656e67696e652e737667)](https://packagist.org/packages/stateflow/engine)[![License](https://camo.githubusercontent.com/9d1db4a76f1169df51ee30bf16b6d3039e4c372777e5c95b50838fc8c93da4ac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7374617465666c6f772f656e67696e652e737667)](https://packagist.org/packages/stateflow/engine)

---

Why StateFlow?
--------------

[](#why-stateflow)

Stop scattering state logic across your codebase:

```
// ❌ Without StateFlow - scattered, error-prone
if ($order->status === 'pending' && $action === 'pay') {
    $order->status = 'paid';
    // Hope you remembered to send the email...
    // Hope you remembered to log it...
    // Hope no other code sets status to something invalid...
}
```

```
// ✅ With StateFlow - clean, auditable, testable
$machine->apply($order, 'pay');
```

FeatureAd-hoc if statementsStateFlowSee all statesScatteredOne placeSee all transitionsScatteredOne placeInvalid transitionsSilent bugsThrows exceptionTyposSilent bugsThrows exceptionSide effectsEasy to forgetDefined with hooksAudit trailBuild it yourselfBuilt-in eventsTestingHardEasyNew developer onboarding"Read the whole codebase""Read this class"---

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

[](#installation)

```
composer require stateflow/engine
```

Requires PHP 8.2 or higher.

---

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

[](#quick-start)

### 1. Define your states and transitions

[](#1-define-your-states-and-transitions)

```
