PHPackages                             cawaphp/statemachine - 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. cawaphp/statemachine

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

cawaphp/statemachine
====================

Сáша StateMachine

0182PHP

Since Feb 27Pushed 8y agoCompare

[ Source](https://github.com/cawaphp/statemachine)[ Packagist](https://packagist.org/packages/cawaphp/statemachine)[ RSS](/packages/cawaphp-statemachine/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Сáша State Machine
==================

[](#сáша-state-machine)

---

Warning
-------

[](#warning)

Be aware that this package is still in heavy developpement. Some breaking change will occure. Thank's for your comprehension.

Features
--------

[](#features)

- State &gt; can have X transitions &gt; can have X conditions
- `getPossibleTransitions()` Possible state depeding on current one
- `getGraph()` Graph of state machine
- `apply($state)` return true or throw a detailled exception
- `apply($state, true)` return bool
- Events :
    - Before state change
    - After state change

Basic Usage
-----------

[](#basic-usage)

```
// Declare the state machine
$stateMachine = new StateMachine("PENDING", new \stdClass());

$stateMachine->addState((new State("PENDING"))
    ->addTransition(new Transition("TOCONFIRM"))
    ->addTransition(new Transition("CONFIRMED"))
);

$stateMachine->addState((new State("TOCONFIRM"))
    ->addTransition(new Transition("CONFIRMED"))
    ->addTransition(new Transition("CANCELED"))
);

$returnTrue = new class extends Condition
{
    public function __invoke($subject) : bool
    {
        return true;
    }
};

$returnFalse = new class extends Condition
{
    public function __invoke($subject) : bool
    {
        return false;
    }
};

$stateMachine->addState((new State("READY"))
    ->addTransition((new Transition("CONFIRMED"))
        ->addCondition($returnFalse)
    )
    ->addTransition((new Transition("PROCESSED"))
        ->addCondition($returnTrue)
    )
    ->addTransition(new Transition("RETURN"))
);

$stateMachine
    ->addState(new State("PROCESSED"))
    ->addState(new State("CANCELED"))
    ->addState(new State("RETURN"));

// play with state

var_dump($stateMachine->getCurrentState()->getName());
// string(7) "PENDING"

$stateMachine->apply("TOCONFIRM");
var_dump($stateMachine->getCurrentState()->getName());
// string(9) "TOCONFIRM"

var_dump($stateMachine->apply("RETURN", true));
// bool(false)
var_dump($stateMachine->getLastException());
// object(Cawa\StateMachine\Exceptions\MissingTransition)#103 (7) {
//   ...
// }

var_dump($stateMachine->getPossibleTransitions());
// array(2) {
//   [0]=>
//   string(9) "CONFIRMED"
//   [1]=>
//   string(8) "CANCELED"
// }

var_dump($stateMachine->getGraph());
// string(369) "digraph G {
//   "PENDING" -> "TOCONFIRM"
//   "PENDING" -> "CONFIRMED"
//   "TOCONFIRM" -> "CONFIRMED"
//   "TOCONFIRM" -> "CANCELED"
//   "READY" -> "CONFIRMED" [label="if (class@anonymous/Test.php0x7fd8eb47c50a)"]
//   "READY" -> "PROCESSED" [label="if (class@anonymous/Test.php0x7fd8eb47c451)"]
//   "READY" -> "RETURN"
// }
// "
```

Method getGraph()
-----------------

[](#method-getgraph)

This method return the raw GraphViz that you can use with official dot executable (`sudo apt-get install graphviz`) or with [this web interface](https://mdaines.github.io/viz.js/)

### License

[](#license)

Cawa is licensed under the GPL v3 License - see the `LICENSE` file for details

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/e49ec71b223035cadd3123f997666dd685f1b3eb355b894a35bd8adeb4da3ba4?d=identicon)[tchiot.ludo](/maintainers/tchiot.ludo)

---

Top Contributors

[![tchiotludo](https://avatars.githubusercontent.com/u/2064609?v=4)](https://github.com/tchiotludo "tchiotludo (10 commits)")

### Embed Badge

![Health badge](/badges/cawaphp-statemachine/health.svg)

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

###  Alternatives

[websharks/html-compressor

Combines &amp; compresses CSS/JS/HTML code.

407.1k1](/packages/websharks-html-compressor)[limewell/laravel-make-extender

This package helps to generate and autoload custom helpers, It can generate multilevel helpers in the context of the directory.

366.8k](/packages/limewell-laravel-make-extender)[linkorb/autotune

Tune your autoloader

177.0k17](/packages/linkorb-autotune)[jayanka/patch-manager

A magento extension to maintain data patches

232.4k](/packages/jayanka-patch-manager)[tapp/filament-progress-bar-column

Add beautiful, color-coded progress bars to your Filament table columns. Perfect for inventory, tasks, storage, and any progress metrics without writing custom views.

124.5k](/packages/tapp-filament-progress-bar-column)

PHPackages © 2026

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