PHPackages                             segfaultinc/finite - 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. segfaultinc/finite

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

segfaultinc/finite
==================

Simple yet powerful Finite State Machine implementation

1.1.0(6y ago)227.1k[1 issues](https://github.com/segfaultinc/finite/issues)MITPHPPHP ^7.2

Since Aug 8Pushed 6y ago1 watchersCompare

[ Source](https://github.com/segfaultinc/finite)[ Packagist](https://packagist.org/packages/segfaultinc/finite)[ Docs](https://github.com/segfaultinc/finite)[ RSS](/packages/segfaultinc-finite/feed)WikiDiscussions master Synced 2w ago

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

WORK IN PROGRESS
================

[](#work-in-progress)

---

Usage
-----

[](#usage)

```
$order = new Order(); // see below
$graph = new Graph(); // see below

$graph->apply($order, 'transition-input');
```

```
use SegfaultInc\Finite\Subject;

class Order extends Model implements Subject
{
    public function setFiniteState($state)
    {
        $this->update([
            'status' => $state,
        ]);
    }

    public function getFiniteState($state)
    {
        return $this->status;
    }
}
```

Graph definition
----------------

[](#graph-definition)

```
(new Graph)
    ->setStates([

        State::initial('new')
            ->label('New')
            ->leaving(function (Order $order) {
                // This is executed every time the `in_progress` is **transitioned from**.
                // Useful if you want to do something that is "state" dependent

                $order->update([
                    'started_at' => now()
                ]);
            }),

        State::normal('in_progress')
            ->label('In Progress'),

        State::final('finished')
            ->label('Finised'),

        State::final('canceled')
            ->label('Canceled')
            ->entering(function (Order $order) {
                // If you transition to "canceled" state from multiple states,
                // this is the place to perform the common logic
            }),

    ])
    ->setTransitions([

        Transition::make('new', 'in_progress', 'progress')
            ->pre(function (Order $order) {
                if ($order->validate()) {
                    throw new OrderValidationException('When an exception is thrown in "pre" hook, the transition is not applied');
                }
            }),

        Transition::make('in_progress', 'finished', 'progress'),

        Transition::make('in_progress', 'canceled', 'cancel')
            ->post(function (Order $order) {
                $order->user->notify(new YourOrderWasCanceled);
            }),

    ]);
```

Visualization
-------------

[](#visualization)

```
$graph->visualize()

// uses GraphViz under the hood
```

[![](https://user-images.githubusercontent.com/4470539/53287565-e4bfff00-3775-11e9-9aea-8b498ba5ac09.png)](https://user-images.githubusercontent.com/4470539/53287565-e4bfff00-3775-11e9-9aea-8b498ba5ac09.png)

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

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

Total

2

Last Release

2453d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4470539?v=4)[Jerguš Lejko](/maintainers/jerguslejko)[@jerguslejko](https://github.com/jerguslejko)

---

Top Contributors

[![jerguslejko](https://avatars.githubusercontent.com/u/4470539?v=4)](https://github.com/jerguslejko "jerguslejko (65 commits)")

---

Tags

finite-state-machinefinitesegfaultinc

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/segfaultinc-finite/health.svg)

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

###  Alternatives

[facuz/laravel-themes

Theme will help you organize your themes inside Laravel projects easily and maintain its related assets, layouts and partials for the theme in single directory. (Based on teepluss/theme)

13743.6k2](/packages/facuz-laravel-themes)[gomachan46/state-machine

simple state machine with annotations for PHP, inspired by AASM known as a Ruby state machine.

1896.3k](/packages/gomachan46-state-machine)[ackintosh/snidel

A multi-process container. It looks like multi-thread-ish.

1051.2k](/packages/ackintosh-snidel)[heptacom/heptaconnect-portal-base

HEPTAconnect base dataset that every other portal is based on

1025.2k15](/packages/heptacom-heptaconnect-portal-base)[infocyph/intermix

A lightweight PHP DI container, invoker, serializer, and utility toolkit.

137.3k1](/packages/infocyph-intermix)[codespede/simple-multi-threader

112.6k](/packages/codespede-simple-multi-threader)

PHPackages © 2026

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