PHPackages                             fedman2010/fsm - 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. fedman2010/fsm

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

fedman2010/fsm
==============

Implementation of Finite State Machine

v1.0.2(10mo ago)04MITPHPPHP ^8.0

Since Aug 28Pushed 10mo agoCompare

[ Source](https://github.com/fedman2010/fsm)[ Packagist](https://packagist.org/packages/fedman2010/fsm)[ RSS](/packages/fedman2010-fsm/feed)WikiDiscussions main Synced today

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

Finite State Machine (FSM)
==========================

[](#finite-state-machine-fsm)

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

[](#installation)

1. Install the package via Composer:

    `composer require fedman2010/fsm`
2. Include the Composer autoloader in your PHP script:

    `include __DIR__ . '/vendor/autoload.php';` to your code.

Usage
-----

[](#usage)

### Step 1: Create the configuration:

[](#step-1-create-the-configuration)

Define the FSM configuration as an associative array with an initial\_state and a rules array that specifies state transitions.Example configuration:

```
$config = [
    'initial_state' => 'idle',
    'rules' => [
        'idle' => [
            [
                'next' => 'running',
                'value' => 'start'
            ],
            [
                'next' => 'stopped',
                'value' => 'stop'
            ]
        ],
        'running' => [
            [
                'next' => 'stopped',
                'value' => 'stop'
            ]
        ],
        'stopped' => [
            [
                'next' => 'idle',
                'value' => 'reset'
            ]
        ]
    ]
];

```

- `initial_state`: The starting state of the FSM (string).
- `rules`: An array where:
    - Keys are state names (string).
    - Values are arrays of transition rules, each containing:
        - `next`: The target state to transition to (string).
        - `value`: The input value that triggers the transition (string or integer).

### Step 2: Initialize the FSM

[](#step-2-initialize-the-fsm)

Create an instance of the FSM with the configuration:

```
use Fedman2010\Fsm\FSM;

$fsm = new FSM($config);

```

### Step 3: Perform Transitions

[](#step-3-perform-transitions)

Use the `transition` method to move between states based on input values:

```
$newState = $fsm->transition('start'); // Transitions to 'running' if current state is 'idle'
echo $newState; // Outputs: running

```

Example
-------

[](#example)

See the `example1.php` and `example2.php` files in the repository for complete, working examples of how to use the FSM.To run the examples in the console, execute:

```
php -f example1.php
php -f example2.php

```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance54

Moderate activity, may be stable

Popularity3

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.

###  Release Activity

Cadence

Every ~1 days

Total

3

Last Release

307d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5364032?v=4)[Maxim](/maintainers/fedman)[@fedman](https://github.com/fedman)

---

Top Contributors

[![fedman2010](https://avatars.githubusercontent.com/u/57632916?v=4)](https://github.com/fedman2010 "fedman2010 (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/fedman2010-fsm/health.svg)

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

PHPackages © 2026

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