winzou/state-machine-bundle
Lightweight PHP/Symfony bundle for defining state machines on your domain objects. Configure graphs with states, transitions, and optional guard/before/after callbacks via YAML/XML/PHP, then apply and test transitions without hard-coded state logic.
draft → review → publish).pending → shipped → delivered).pending → approved → suspended).submitted → rejected → appealed).Adopt If:
pending_review to published if approved").SM\Debug\DebugCommand for Symfony CLI).Look Elsewhere If:
"This package lets us define workflows (e.g., content approvals, order processing) in simple configs instead of scattered code. It reduces bugs from hard-coded state logic, makes workflows easier to update, and integrates seamlessly with our Symfony stack. For example, we could cut content moderation delays by 30% by automating state transitions and notifications—all without rewriting business logic."
Key Benefits:
*"This is a battle-tested, lightweight state machine for Symfony that replaces messy if-else chains with declarative YAML configs. Key features:
publish if content is flagged).Example Use Case: Replace this:
if ($article->state === 'pending_review' && $reviewer->isApproved()) {
$article->state = 'published';
$this->emailService->send($article);
}
With this (config-driven):
transitions:
publish:
from: [pending_review]
to: published
callbacks:
after:
email_on_publish:
on: publish
do: ['@email_service', 'send']
args: ['object']
Why Not Build It?
How can I help you explore Laravel packages today?