Skip to content
KUBO Atsuhiro edited this page Nov 1, 2013 · 13 revisions

Stagehand_FSM - A finite state machine

Stagehand_FSM is a finite state machine (FSM).

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, page flow engines such as Piece_Flow.

<?php
use Stagehand\FSM\StateMachine\StateMachineBuilder;

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

$stateMachine->start();
echo $stateMachine->getCurrentState()->getStateID() . PHP_EOL; // "locked"
$stateMachine->triggerEvent('insertCoin');
echo $stateMachine->getCurrentState()->getStateID() . PHP_EOL; // "unlocked"
$stateMachine->triggerEvent('pass');
echo $stateMachine->getCurrentState()->getStateID() . PHP_EOL; // "locked"

Features

  • Activities (Do Actions)
  • Entry Actions
  • Exit Actions
  • Transition Actions
  • Guards
  • Initial Pseudo State
  • Final State
  • User-Defined Payload

Requirements

  • PHP 5.3.2 or greater

Installation

Package Version Stability Release Date License
Stagehand_FSM 2.0.0 stable 2013-08-01 The BSD 2-Clause License Release Notes

Stagehand_FSM can be installed using Composer or PEAR. The following sections explain how to install Stagehand_FSM.

Composer

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

{
    "require": {
        "piece/stagehand-fsm": ">=2.0.0"
    }
}

Second, update your dependencies as the following:

composer update piece/stagehand-fsm

PEAR

pear config-set auto_discover 1
pear install pear.piece-framework.com/Stagehand_FSM

Documentation

Source

Browse Source Code

Browse Source Code

Git Access

git clone https://github.com/piece/stagehand-fsm.git

Support

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

Copyright (c) 2006-2008, 2011-2013 KUBO Atsuhiro <kubo@iteman.jp>, All rights reserved.

License

The BSD 2-Clause License

Clone this wiki locally