A finite state machine

Installs: 1 998

Dependents: 3

Stars: 14

Watchers: 3

Forks: 2

Open Issues: 1

v2.4.0 2015-07-12 03:18 UTC


A finite state machine

Total Downloads Latest Stable Version Latest Unstable Version Build Status

Stagehand_FSM is a finite state machine.

Manual state management makes code complex, decreases intentionality. By using Stagehand_FSM, state management code can be declaratively represented in the form of FSM. This makes code simpler, increases intentionality.

Stagehand_FSM can be used as an infrastructure for domain-specific languages (DSLs). Examples are workflow engines such as Workflower, pageflow engines such as PHPMentorsPageflowerBundle.

use Stagehand\FSM\StateMachine\StateMachineBuilder;

$stateMachineBuilder = new StateMachineBuilder();
$stateMachineBuilder->addTransition('locked', 'insertCoin', 'unlocked');
$stateMachineBuilder->addTransition('unlocked', 'pass', 'locked');
$stateMachine = $stateMachineBuilder->getStateMachine();

echo $stateMachine->getCurrentState()->getStateID() . PHP_EOL; // "locked"
echo $stateMachine->getCurrentState()->getStateID() . PHP_EOL; // "unlocked"
echo $stateMachine->getCurrentState()->getStateID() . PHP_EOL; // "locked"


  • Activities (do actions)
  • Entry actions
  • Exit actions
  • Transition actions
  • Transition logging
  • Guards
  • Initial pseudo state
  • Final state
  • User-defined payload
  • User-defined event dispatcher for the state machine events


Stagehand_FSM can be installed using Composer.

Add the dependency to piece/stagehand-fsm into your composer.json file as the following:

Stable version:

composer require piece/stagehand-fsm "2.4.*"

Development version:

composer require piece/stagehand-fsm "~2.5@dev"


If you find a bug or have a question, or want to request a feature, create an issue or pull request for it on Issues.


Copyright (c) 2006-2008, 2011-2015 KUBO Atsuhiro, All rights reserved.


The BSD 2-Clause License