Example #1
0
 /**
  * @param StateObjectInterface $model
  * @param StateInterface $targetStatus
  * @return void
  */
 public function process(StateObjectInterface $model, StateInterface $targetStatus)
 {
     if (!$this->can($model, $targetStatus)) {
         throw new CantSetStatusException(sprintf('There is no transition from "%s" to "%s"', $model->getState()->getName(), $targetStatus->getName()));
     }
     $event = new TransitionEvent($model, $targetStatus, $this->getEventKey($model->getState(), $targetStatus));
     $this->eventDispatcher->emit($event);
     $model->setState($targetStatus);
 }
 /**
  * @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);
 }