From 23f2b6ef8319fc0b55d92d3cf5c1cf1ebf3d0fc9 Mon Sep 17 00:00:00 2001 From: Alejandro Hurtado Date: Tue, 24 Feb 2015 17:08:10 +0100 Subject: [PATCH] to reject the event The [issue 77] (https://github.com/yohang/Finite/issues/77) explain the problem. I suggest this change to resolve it. --- src/Finite/StateMachine/StateMachine.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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());