winzou/state-machine
Lightweight PHP state machine library. Define graphs with states, transitions, and guard/before/after callbacks, then apply and validate transitions on your domain objects. Supports multiple graphs per object and configurable state property paths.
draft → published → archived). MIT license and 500+ stars signal community trust.pending → shipped → delivered with guards (e.g., "block ship if payment_failed").trial → paid → cancelled with callbacks (e.g., send renewal reminders on paid).Invoice with payment_status and audit_status graphs).after callbacks to satisfy audit trails (e.g., GDPR, SOX).if-else checks.cancel if confirmed") or side effects (e.g., send emails on shipped).Order with payment + shipping workflows).For Executives:
*"This package eliminates workflow chaos by turning business rules (e.g., ‘orders can’t ship unless paid’) into configurable state machines. Instead of scattered if-else checks, we define transitions once and enforce them everywhere. For example:
pending → shipped → delivered with automatic validation.trial → paid → cancelled with email triggers.It’s lightweight, open-source, and integrates with our Laravel stack—no new infrastructure needed. Think of it as guardrails for our processes with zero dev overhead."*
For Engineers: *"winzou/state-machine lets us declare workflows instead of embedding them in business logic. Key perks:
cancel if confirmed).before/after transitions (e.g., send Slack alerts, log actions).Order with payment + shipping workflows).state field in your model.Example:
// Define an order workflow:
$config = [
'states' => ['pending', 'shipped', 'delivered', 'cancelled'],
'transitions' => [
'ship' => ['from' => 'pending', 'to' => 'shipped'],
'cancel' => ['from' => ['pending', 'shipped'], 'to' => 'cancelled'],
],
'callbacks' => [
'guard' => [
'block-ship' => [
'from' => 'pending',
'do' => fn(Order $order) => !$order->payment->is_paid(),
],
],
'after' => [
'notify-shipped' => [
'on' => 'ship',
'do' => fn(Order $order) => $order->sendShippingEmail(),
],
],
],
];
Why not DIY?
Trade-offs:
after callbacks).0.x, but MIT license and active contributions reduce risk.How can I help you explore Laravel packages today?