- converted class names and directories for PSR0 - replaced the basic __autoload() by the canonical PSR0 loader example. - added a GraphViz-based Grapher class to plot Machine structures.
62 lines
1.3 KiB
PHP
62 lines
1.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Finite state machine skeleton
|
|
*
|
|
* @copyright (c) 2007-2012 Ouest Systèmes Informatiques
|
|
* @author Frédéric G. MARAND
|
|
* @license Licensed under the CeCILL 2.0
|
|
* @link http://wiki.audean.com/fsm/fsm
|
|
*
|
|
* @todo replace setAttribute('id',...) by setIdAttribute when PHP5.2 becomes mandatory
|
|
*/
|
|
|
|
namespace OSInet\Finite_State_Machine;
|
|
|
|
/**
|
|
* needed notably for func_name()
|
|
*/
|
|
require_once('misc.php'); // for func_name()
|
|
|
|
$erFiniteStateMachine = error_reporting(-1);
|
|
|
|
/**
|
|
* This class defines a possible outcome for a given FSM transition.
|
|
*/
|
|
class Result {
|
|
/**
|
|
* The return value of the event handler.
|
|
*
|
|
* @var mixed
|
|
*/
|
|
public $fsmReturn;
|
|
|
|
/**
|
|
* The name of the state to which the FSM must change.
|
|
*
|
|
* If NULL, do not change the current state.
|
|
*
|
|
* @var string
|
|
*/
|
|
public $fsmState;
|
|
|
|
/**
|
|
* The name of an event to be fired after the state change has been applied.
|
|
*
|
|
* @var string
|
|
*/
|
|
public $fsmAction;
|
|
|
|
/**
|
|
* @param string $state
|
|
* @param string $action
|
|
*/
|
|
public function __construct($return = NULL, $state = NULL, $action = NULL) {
|
|
$this->fsmReturn = $return;
|
|
$this->fsmState = $state;
|
|
$this->fsmAction = $action;
|
|
}
|
|
}
|
|
|
|
error_reporting($erFiniteStateMachine);
|
|
unset($erFiniteStateMachine);
|