Download the PHP package benrowe/stateflow without Composer
On this page you can find all versions of the php package benrowe/stateflow. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download benrowe/stateflow
More information about benrowe/stateflow
Files in benrowe/stateflow
Package stateflow
Short Description A flexible state machine library for PHP
License MIT
Informations about the package stateflow
StateFlow
A powerful state workflow engine for PHP that handles complex state transitions with built-in observability and race condition prevention.
Why StateFlow?
Most state machines force you into rigid patterns. StateFlow is different:
- 🎯 Delta-Based Transitions - Specify only what changes, not the entire state
- ⚙️ Granular Execution Control - Manage workflow execution at the per-action level
- 🔒 Race-Safe by Design - Built-in mutex locking prevents concurrent modification
- 👀 Fully Observable - Events fired at every step for monitoring and debugging
- 🎨 Flexible Validation - Two-tier gates (transition-level + action-level)
- 📦 Serializable Context - Pause, store, and resume workflows hours or days later
- 🔧 User-Controlled - You define state structure, merge strategy, and lock behavior
Perfect For
- E-commerce order processing with payment/inventory/shipping workflows
- Content publishing pipelines with approval stages and notifications
- Long-running batch jobs that need checkpointing
- Multi-step user onboarding flows
- Any scenario where state transitions need audit trails and concurrency control
Quick Example
Key Features
🎯 Delta-Based Transitions
Specify only what changes:
⚙️ Granular Execution Control
The StateWorker gives you full control over the workflow execution:
🔒 Race Condition Prevention
Built-in mutex locking, configured on the StateFlow:
If another process tries to transition the same entity, it will wait, fail, or skip based on your lock provider's behavior.
👀 Fully Observable
Every step emits events:
🎨 Two-Tier Validation
Transition Gates - Must pass for transition to begin:
Action Gates - Skip individual actions if guard fails:
Installation
Requirements: PHP 8.2+
Documentation
📚 Comprehensive documentation available in the docs/ directory:
| Document | Description |
|---|---|
| Architecture Overview | Design goals and principles |
| Flow Diagrams | Visual flowcharts (Mermaid) |
| Core Concepts | State, Gates, Actions, Configuration |
| Observability | Event system and monitoring |
| Locking System | Race condition handling |
| Interface Reference | Complete API documentation |
| Usage Examples | Real-world patterns |
Real-World Example
E-Commerce Order Processing
What Makes StateFlow Different?
| Feature | StateFlow | Traditional State Machines |
|---|---|---|
| Granular Control | ✅ Per-action execution & pause/resume | ❌ Must complete in one execution |
| Race-Safe | ✅ Built-in mutex locking | ❌ Manual coordination required |
| Observable | ✅ Events at every step | ❌ Limited visibility |
| Flexible State | ✅ User-defined merge strategy | ❌ Rigid state structure |
| Lazy Config | ✅ Load gates/actions on-demand | ❌ All configured upfront |
| Lock Persistence | ✅ Lock held across pauses | ❌ N/A |
| Execution Trace | ✅ Complete audit trail | ❌ Limited history |
Status
🚧 Alpha Stage
The architecture is designed and documented. The project is under active development.
Contributing
Contributions welcome! See Contributing Guide for development setup and guidelines.
License
The MIT License (MIT). See LICENSE for details.
Credits
- Ben Rowe
- All Contributors
Built with ❤️ for developers who need powerful, observable, race-safe workflows.