You are here

class StateMachine_Test in State Machine 6

Same name and namespace in other branches
  1. 7.3 tests/state_machine.test \StateMachine_Test
  2. 7 tests/state_machine.test \StateMachine_Test
  3. 7.2 tests/state_machine.test \StateMachine_Test

Hierarchy

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

Namesort descending Modifiers Type Description Overrides
StateMachine::$current protected property
StateMachine::$events protected property
StateMachine::$initial protected property
StateMachine::$object protected property
StateMachine::$states protected property
StateMachine::create_event 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::create_state 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::fire_event public function Trigger an event to process a transition. Callbacks and guard conditions will be processed in the following order:
StateMachine::get_available_events public function Returns an array of events that are valid for the current state.
StateMachine::get_current_state public function Returns the current state.
StateMachine::get_event protected function Return an event instance by key, lazy-loading the instance if necessary. 1
StateMachine::get_state protected function Return a state instance by key, lazy-loading the instance if necessary.
StateMachine::load protected function Load the current state from the given state storage 1
StateMachine::on_event_fail protected function Method to be called when firing an event fails for any reason.
StateMachine::persist protected function Persist the current state to the object storage. 1
StateMachine::set_current_state protected function Set the current state to the state identified by the specified key.
StateMachine::set_initial_state protected function Set the initial state for this machine. By default, the initial state is set the the first created state.
StateMachine::__construct public function
StateMachine_Test::$logs public property
StateMachine_Test::guard_with_your_life public function
StateMachine_Test::init public function Called from StateMachine::__construct to initialize the states and events. Overrides StateMachine::init
StateMachine_Test::log_after_transition public function
StateMachine_Test::log_before_transition public function
StateMachine_Test::log_callback public function
StateMachine_Test::log_on_enter public function
StateMachine_Test::log_on_exit public function
StateMachine_Test::log_on_guard public function
StateMachine_Test::reset_logs public function