/**
  * Sets the exit action to the state.
  *
  * @param string   $stateId
  * @param callback $action
  *
  * @throws ActionNotCallableException
  * @throws StateNotFoundException
  */
 public function setExitAction($stateId, $action)
 {
     $state = $this->stateMachine->getState($stateId);
     if ($state === null) {
         throw new StateNotFoundException(sprintf('The state "%s" is not found in the state machine "%s".', $stateId, $this->stateMachine->getStateMachineId()));
     }
     if (!is_callable($action)) {
         throw new ActionNotCallableException(sprintf('The action for the event "%s" in the state "%s" is not callable.', EventInterface::EVENT_EXIT, $stateId));
     }
     $state->getEvent(EventInterface::EVENT_EXIT)->setAction($action);
 }
 /**
  * Adds an state transition to the state machine.
  *
  * @param string $stateId
  * @param string $eventId
  * @param string $nextStateId
  *
  * @throws StateNotFoundException
  */
 public function addTransition($stateId, $eventId, $nextStateId)
 {
     $state = $this->stateMachine->getState($stateId);
     if ($state === null) {
         throw new StateNotFoundException(sprintf('The state "%s" is not found.', $stateId));
     }
     $event = $state->getEvent($eventId);
     if ($event === null) {
         $event = new TransitionEvent($eventId);
     }
     $nextState = $this->stateMachine->getState($nextStateId);
     if ($nextState === null) {
         throw new StateNotFoundException(sprintf('The state "%s" is not found.', $nextStateId));
     }
     $this->stateMachine->addTransition(new Transition($nextState, $state, $event));
 }