class StateMachine_Test in State Machine 6
Same name and namespace in other branches
- 7.3 tests/state_machine.test \StateMachine_Test
- 7 tests/state_machine.test \StateMachine_Test
- 7.2 tests/state_machine.test \StateMachine_Test
Hierarchy
- class \StateMachine
- class \StateMachine_Test
Expanded class hierarchy of StateMachine_Test
File
- tests/
state_machine.test, line 5
View source
class StateMachine_Test extends StateMachine {
/**
* Called from StateMachine::__construct to initialize the states and events.
*/
public function init() {
$this
->create_state('step1', array(
'on_exit' => array(
$this,
'log_on_exit',
),
));
$this
->create_state('step2', array(
'on_enter' => array(
$this,
'log_on_enter',
),
));
$this
->create_state('step3', array());
$this
->create_event('goto2', array(
'origin' => 'step1',
'target' => 'step2',
));
$this
->create_event('goto2_with_logs', array(
'origin' => 'step1',
'target' => 'step2',
'guard' => array(
$this,
'log_on_guard',
),
'before_transition' => array(
$this,
'log_before_transition',
),
'after_transition' => array(
$this,
'log_after_transition',
),
));
$this
->create_event('goto3', array(
'origin' => array(
'step1',
'step2',
),
'target' => 'step3',
'guard' => FALSE,
'onTransition' => FALSE,
));
$this
->create_event('reset', array(
'origin' => array(
'step2',
'step3',
),
'target' => 'step1',
));
$this
->create_event('dont_do_it', array(
'origin' => array(
'step1',
'step2',
'step3',
),
'target' => 'step1',
'guard' => array(
$this,
'guard_with_your_life',
),
));
}
public $logs = array();
public function reset_logs() {
$this->logs = array();
}
public function log_callback($callback) {
$this->logs[] = $callback;
}
public function log_on_guard() {
$this
->log_callback('guard');
}
public function log_before_transition() {
$this
->log_callback('before_transition');
}
public function log_after_transition() {
$this
->log_callback('after_transition');
}
public function log_on_enter() {
$this
->log_callback('on_enter');
}
public function log_on_exit() {
$this
->log_callback('on_exit');
}
public function guard_with_your_life() {
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StateMachine:: |
protected | property | ||
StateMachine:: |
protected | property | ||
StateMachine:: |
protected | property | ||
StateMachine:: |
protected | property | ||
StateMachine:: |
protected | property | ||
StateMachine:: |
protected | function | Create a new event. This method does not actually create an event instance, it only stores the options array until an instance is requested from get_event(). | |
StateMachine:: |
protected | function | Create a new state. This method does not actually create a state instance, it only stores the options array until an instance is requested from get_state(). | |
StateMachine:: |
public | function | Trigger an event to process a transition. Callbacks and guard conditions will be processed in the following order: | |
StateMachine:: |
public | function | Returns an array of events that are valid for the current state. | |
StateMachine:: |
public | function | Returns the current state. | |
StateMachine:: |
protected | function | Return an event instance by key, lazy-loading the instance if necessary. | 1 |
StateMachine:: |
protected | function | Return a state instance by key, lazy-loading the instance if necessary. | |
StateMachine:: |
protected | function | Load the current state from the given state storage | 1 |
StateMachine:: |
protected | function | Method to be called when firing an event fails for any reason. | |
StateMachine:: |
protected | function | Persist the current state to the object storage. | 1 |
StateMachine:: |
protected | function | Set the current state to the state identified by the specified key. | |
StateMachine:: |
protected | function | Set the initial state for this machine. By default, the initial state is set the the first created state. | |
StateMachine:: |
public | function | ||
StateMachine_Test:: |
public | property | ||
StateMachine_Test:: |
public | function | ||
StateMachine_Test:: |
public | function |
Called from StateMachine::__construct to initialize the states and events. Overrides StateMachine:: |
|
StateMachine_Test:: |
public | function | ||
StateMachine_Test:: |
public | function | ||
StateMachine_Test:: |
public | function | ||
StateMachine_Test:: |
public | function | ||
StateMachine_Test:: |
public | function | ||
StateMachine_Test:: |
public | function | ||
StateMachine_Test:: |
public | function |