izzum\statemachine\StateMachine::transition PHP Method

transition() public method

this type of handling is found in moore machines.
public transition ( string $transition_name, string $message = null ) : boolean
$transition_name string convention: _to_
$message string optional message. this can be used by the persistence adapter to be part of the transition history to provide extra information about the transition.
return boolean true if the transition was made
    public function transition($transition_name, $message = null)
    {
        $transition = $this->getTransitionWithNullCheck($transition_name);
        return $this->performTransition($transition, $message);
    }

Usage Example

     //too much good times
     echo "Ahw man...! Try not to drink/smoke as much next time, it's bad for you ;)" . PHP_EOL . PHP_EOL;
     exit;
 }
 foreach ($state->getTransitions() as $transition) {
     echo "'" . $transition->getName() . "' aka event '" . $transition->getEvent() . "'" . PHP_EOL;
 }
 echo PHP_EOL;
 //get input from the user
 $event = readline("Enter an event or transition name: ");
 try {
     $status = 0;
     $transitioned = false;
     //we allow transitions by name or by event
     if (strstr($event, '_to_')) {
         $transitioned = $machine->transition($event);
         if ($transitioned) {
             $status = 1;
         }
     } else {
         $transitioned = $machine->handle($event);
         if ($transitioned) {
             $status = 2;
         }
     }
 } catch (\Exception $e) {
     //for instance, when providing a bad transition name.
     echo "An exception occured: " . $e->getMessage() . PHP_EOL;
 }
 //check what happened
 switch ($status) {