PHPackages                             tiddr/state\_machine - 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. tiddr/state\_machine

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

tiddr/state\_machine
====================

313[1 issues](https://github.com/tiw/state_machine/issues)PHP

Since May 16Pushed 11y ago1 watchersCompare

[ Source](https://github.com/tiw/state_machine)[ Packagist](https://packagist.org/packages/tiddr/state_machine)[ RSS](/packages/tiddr-state-machine/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependenciesVersions (4)Used By (0)

[![Build status](https://camo.githubusercontent.com/002bac0a75c0400f3433d37b6be0677c872c4a6bf6955a9008b58124e80c1580/687474703a2f2f7472617669732d63692e6f72672f7469772f73746174655f6d616368696e652e7376673f6272616e63683d646576656c6f70)](http://travis-ci.org/tiw/state_machine)

state\_machine
==============

[](#state_machine)

[中文介绍](https://github.com/tiw/state_machine/blob/master/README_cn.md)

A state machine implemetation in PHP. This implementation is mostly inspired from "Domain Specifi Languages" of Martin Flower.

State Machine in essential is a collection of State, Event and Transistion.

```

+---------+               +---------+
|         |               |         |
|         +---------------+         |
+---------+               +---------+
    State1     Event        target

```

In this implementation the description of a state machine could be written in yml.

An example state machine could be like:

```
Name: door

Start: "dc"

Event:
- ["close door", "CD"]
- ["open door", "OD"]
- ["open window", "OW"]
- ["close window", "CW"]

State:
- "dc"
- "do"
- "wo"
- "wc"

Transition:
- ["dc", "OD", "do"]
- ["do", "OW", "wo"]
- ["wo", "CW", "wc"]
- ["do", "CD", "dc"]

```

In '''Event''' block all events are listed in the format \[name, code\]. Code must be unique. This code is also used to drive the machine.

In '''State''' block all states are listed in the format "name".

In '''Transition''' block all transitions are listed in the format \[startState, event, targetState\].

The sample use of state machine and controller could be see in the test directory.

Install per Composer
====================

[](#install-per-composer)

```
{

    "require": {
        "tiddr/state_machine": "dev-master"
    }
}

```

Then just add

```
require_once __DIR__.'/vendor/autoload.php';

```

Example
=======

[](#example)

Take a look at the files under directory [tests](https://github.com/tiw/state_machine/tree/master/tests)

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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/f86b6ffbeef3821dcc7e82e94240e3eb0f485704ddd5e541a82f6f98d73cbf61?d=identicon)[tiw](/maintainers/tiw)

---

Top Contributors

[![tiw](https://avatars.githubusercontent.com/u/151735?v=4)](https://github.com/tiw "tiw (43 commits)")

### Embed Badge

![Health badge](/badges/tiddr-state-machine/health.svg)

```
[![Health](https://phpackages.com/badges/tiddr-state-machine/health.svg)](https://phpackages.com/packages/tiddr-state-machine)
```

###  Alternatives

[armincms/many-to-many

A Laravel Nova field.

2574.7k3](/packages/armincms-many-to-many)[mickey-kay/better-font-awesome-library

Better Font Awesome Library for WordPress

371.8k1](/packages/mickey-kay-better-font-awesome-library)

PHPackages © 2026

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