/** * @param TransitionInterface $transition * @param StateInterface $sourceState * @param StateInterface $targetState */ public function addTransition(TransitionInterface $transition, StateInterface $sourceState, StateInterface $targetState) { $this->addState($sourceState); $this->addState($targetState); $this->transitions[] = $transition; if (!isset($this->transitionStatesFlow[$sourceState->getId()])) { $this->transitionStatesFlow[$sourceState->getId()] = array(); } $this->transitionStatesFlow[$sourceState->getId()][] = $targetState->getId(); $this->transitionsStates[$transition->getName()] = array($sourceState->getId(), $targetState->getId()); $transitionSubscription = new Subscription($this->getEventKey($sourceState, $targetState), function (TransitionEvent $event) use($transition) { $transition->processTransaction($event->getModel(), $event->getTargetState()); }); $this->eventDispatcher->subscribe($transitionSubscription); }
/** * @test */ public function fireEvent_stopPropagation() { $eventDispatcher = new EventDispatcher(); $event = new EventDispatcher\Event('fooBar'); $subscription1 = new EventDispatcher\Subscription('fooBar', function (EventDispatcher\EventInterface $event) use(&$eventHistory) { $eventHistory[] = 'first'; $event->stopPropagation(); }); $eventDispatcher->subscribe($subscription1); $subscription2 = new EventDispatcher\Subscription('fooBar', function ($event) use(&$eventHistory) { $eventHistory[] = 'second'; }); $eventDispatcher->subscribe($subscription2); $eventDispatcher->emit($event); $this->assertEquals(array('first'), $eventHistory); }