/** * Adds an state transition to the state machine. * * @param string $stateId * @param string $eventId * @param string $nextStateId * @param callback $action * @param callback $guard * * @throws ActionNotCallableException * @throws StateNotFoundException */ public function addTransition($stateId, $eventId, $nextStateId, $action = null, $guard = null) { $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)); } if ($action !== null) { if (!is_callable($action)) { throw new ActionNotCallableException(sprintf('The action for the event "%s" in the state "%s" is not callable.', $eventId, $stateId)); } } if ($guard !== null) { if (!is_callable($guard)) { throw new ActionNotCallableException(sprintf('The guard for the event "%s" in the state "%s" is not callable.', $eventId, $stateId)); } } $this->stateMachine->addTransition($state, $event, $nextState, $action, $guard); }
/** * 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)); }