diff --git a/src/Finite/StateMachine/StateMachine.php b/src/Finite/StateMachine/StateMachine.php index 3be6a7b..b203365 100644 --- a/src/Finite/StateMachine/StateMachine.php +++ b/src/Finite/StateMachine/StateMachine.php @@ -120,7 +120,11 @@ public function apply($transitionName) { $transition = $this->getTransition($transitionName); $event = new TransitionEvent($this->getCurrentState(), $transition, $this); - if (!$this->can($transition)) { + + $this->dispatcher->dispatch(FiniteEvents::PRE_TRANSITION, $event); + $this->dispatcher->dispatch(FiniteEvents::PRE_TRANSITION.'.'.$transitionName, $event); + + if (!$this->can($event->getTransition()) || $event->isRejected()) { throw new Exception\StateException(sprintf( 'The "%s" transition can not be applied to the "%s" state of object "%s" with graph "%s".', $transition->getName(), @@ -130,9 +134,6 @@ public function apply($transitionName) )); } - $this->dispatcher->dispatch(FiniteEvents::PRE_TRANSITION, $event); - $this->dispatcher->dispatch(FiniteEvents::PRE_TRANSITION . '.' . $transitionName, $event); - $returnValue = $transition->process($this); $this->stateAccessor->setState($this->object, $transition->getState()); $this->currentState = $this->getState($transition->getState());