If the event is applicable for a transition then that transition from the
current state will be applied.
If there are multiple transitions possible for the event, the transitions
will be tried until one of them is possible.
This type of (event/trigger) handling is found in mealy machines.
public handle ( string $event, string $message = null ) : boolean | ||
$event | string | in case the transition will be triggered by an event code
(mealy machine)
this will also match on the transition name
( |
$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 in case a transition was triggered by the event, false otherwise |
echo "'" . $transition->getName() . "' aka event '" . $transition->getEvent() . "'" . PHP_EOL; } echo PHP_EOL; //get input from the user $event = readline("[01;32mEnter an [01;36mevent [01;32mor [01;34mtransition [01;32mname: [0m"); 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 "[31mAn exception occured: " . $e->getMessage() . PHP_EOL; } //check what happened switch ($status) { case 1: echo "[01;34m--- transition by transition name '{$event}' succesful"; break; case 2: echo "[01;36m--- transition by event name '{$event}' succesful";