PHPackages                             jooservices/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. jooservices/state-machine

ActiveLibrary

jooservices/state-machine
=========================

A PHP 8.5+ configuration-driven finite state machine for any PHP object

00

Since Jul 21Compare

[ Source](https://github.com/jooservices/state-machine)[ Packagist](https://packagist.org/packages/jooservices/state-machine)[ RSS](/packages/jooservices-state-machine/feed)WikiDiscussions Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

JOOservices State Machine
=========================

[](#jooservices-state-machine)

[![CI](https://github.com/jooservices/state-machine/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/jooservices/state-machine/actions/workflows/ci.yml)[![OpenSSF Scorecard](https://camo.githubusercontent.com/55e77e5bbb4db07fea6ea2f87e7491ba110f9a8f7decdc8e1cc9b597dba6ee19/68747470733a2f2f6170692e736563757269747973636f726563617264732e6465762f70726f6a656374732f6769746875622e636f6d2f6a6f6f73657276696365732f73746174652d6d616368696e652f6261646765)](https://securityscorecards.dev/viewer/?uri=github.com/jooservices/state-machine)[![PHP Version](https://camo.githubusercontent.com/2788132aa1e54031a6c94edcbf8688566d3e18cb5492cd1766836f74a24b27b5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e352532422d626c75652e737667)](https://www.php.net/)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](LICENSE)[![Packagist Version](https://camo.githubusercontent.com/cb62725bab60ac9cbaadb09fce49a224c5d14aef6299890d7d32c461ed0dffa2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6f6f73657276696365732f73746174652d6d616368696e65)](https://packagist.org/packages/jooservices/state-machine)

The **JOOservices State Machine** is a PHP 8.5+ configuration-driven finite state machine for any PHP object — DTOs, POPOs, or framework models. Zero framework coupling. State is a string property on the subject.

Package name: `jooservices/state-machine`

Latest stable release: `v1.0.0`

Install
-------

[](#install)

```
composer require jooservices/state-machine
```

Quick example
-------------

[](#quick-example)

```
use JOOservices\StateMachine\StateMachineFactory;

final class Order
{
    public function __construct(
        public string $status = 'pending',
    ) {}
}

$config = [
    'property' => 'status',
    'states' => ['pending', 'confirmed', 'shipped', 'cancelled'],
    'initial_state' => 'pending',
    'transitions' => [
        'confirm' => ['from' => ['pending'], 'to' => 'confirmed'],
        'ship' => ['from' => ['confirmed'], 'to' => 'shipped'],
        'cancel' => ['from' => ['pending', 'confirmed'], 'to' => 'cancelled'],
    ],
];

$order = new Order();
$machine = (new StateMachineFactory())->create($order, 'order', $config);

if ($machine->can('confirm')) {
    $machine->apply('confirm');
}

echo $machine->getState(); // confirmed
```

What is supported today
-----------------------

[](#what-is-supported-today)

- configuration-driven graphs validated at construction time
- `can()` / `apply()` / `getAvailableTransitions()`
- pluggable state accessors (property reflection or getter/setter)
- guards and before/after callbacks as class strings
- optional PSR-14 lifecycle events
- multiple independent graphs per subject (separate machine instances)
- pure PHP 8.5+ with no Laravel/Symfony runtime requirement

Important current limitations
-----------------------------

[](#important-current-limitations)

- guards and callbacks are constructed with `new $class()` (no container resolution)
- event dispatcher is optional; consumers bring their own PSR-14 implementation
- no built-in persistence, Eloquent casts, or service providers
- missing properties/methods are handled conservatively by accessors (null / no-op)

Documentation
-------------

[](#documentation)

Start with:

- [Documentation Hub](./docs/README.md)
- [Changelog](./CHANGELOG.md)
- [AI Skills Usage Guide](./ai/skills/USAGE.md)
- phpDocumentor config: [`phpdoc.dist.xml`](./phpdoc.dist.xml)
- [Installation](./docs/01-getting-started/01-installation.md)
- [Quick Start](./docs/01-getting-started/02-quick-start.md)
- [Risks, Legacy, and Gaps](./docs/05-maintenance/01-risks-legacy-and-gaps.md)

AI Support
----------

[](#ai-support)

This repository includes an AI skill pack for agents working in Cursor, Claude Code, VS Code, JetBrains, and Antigravity.

Start with:

- [`AGENTS.md`](./AGENTS.md)
- [`CLAUDE.md`](./CLAUDE.md)
- [AI Skills Map](./ai/skills/README.md)
- [AI Skills Usage Guide](./ai/skills/USAGE.md)

The canonical skill source lives in [`.github/skills/`](./.github/skills/), with adapter layers for each supported AI environment.

Development
-----------

[](#development)

```
composer lint
composer lint:all
composer test
composer test:coverage
composer check
composer ci
```

Contributor workflow details live in:

- [Setup](./docs/04-development/01-setup.md)
- [Contributing](./docs/04-development/07-contributing.md)
- [CI/CD](./docs/04-development/05-ci-cd.md)
- [Release Process](./docs/04-development/06-release-process.md)
- [AI Skills](./docs/04-development/08-ai-skills.md)

Approved Git flow summary:

- normal feature and fix work branches from `develop` and PRs back into `develop`
- release preparation uses `release/` from `develop`, then PRs into `master`
- releases are tagged from `master`
- `master` merges back into `develop` after release or hotfix completion

Community
---------

[](#community)

- [Contributing](./CONTRIBUTING.md)
- [Security Policy](./SECURITY.md)
- [Code of Conduct](./CODE_OF_CONDUCT.md)

GitHub Actions and Services
---------------------------

[](#github-actions-and-services)

Current GitHub Actions coverage:

- `CI`: security checks, linting, tests, 95% minimum statement coverage, coverage upload, and optional SonarQube Cloud analysis when `SONAR_TOKEN` is configured
- `Release`: validate tags, create GitHub releases, trigger Packagist update
- `PR Labeler`: apply labels to pull requests
- `Semantic PR Title`: enforce pull request title format
- `OpenSSF Scorecard`: publish scorecard results as SARIF
- `Secret Scanning`: workflow file exists, but the `gitleaks` job may be disabled depending on repository settings

External services currently used by workflows:

- `Codecov` for coverage upload in [`ci.yml`](./.github/workflows/ci.yml)
- `Packagist` update webhook in [`release.yml`](./.github/workflows/release.yml)
- `GitHub Releases` and `GitHub Discussions` in [`release.yml`](./.github/workflows/release.yml)
- `OpenSSF Scorecard` in [`scorecard.yml`](./.github/workflows/scorecard.yml)

License
-------

[](#license)

This project is licensed under the [MIT License](./LICENSE).

###  Health Score

9

—

LowBetter than 0% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

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://avatars.githubusercontent.com/u/142772948?v=4)[JOOservices Ltd](/maintainers/jooservices)[@jooservices](https://github.com/jooservices)

### Embed Badge

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

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

PHPackages © 2026

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