/** * {@inheritdoc} */ public function dispatch($eventName, SymfonyEvent $event = null) { parent::dispatch($eventName, $event); if (null === $event) { $event = new SymfonyEvent(); } $this->em->emit(new SilexEvent($eventName, $event)); return $event; }
/** * {@inheritdoc} */ public function emit(Event $event) { $name = $this->getEventName($event); $this->stopwatch->start($name); parent::emit($event); $this->stopwatch->stop($name); }
public function testEmittedEventRunsThroughAnonymousListenersInProperOrder() { $event = new \DummyEvent(); $em = new EventManager(); $calls = array(); $listeners[] = new AnonymousListener(function (Event $event) use(&$calls) { if ($event instanceof \DummyEvent) { $event->calls[] = 'A'; } }); $listeners[] = new AnonymousListener(function (Event $event) use(&$calls) { if ($event instanceof \DummyEvent) { $event->calls[] = 'B'; } }); $listeners[] = new AnonymousListener(function (Event $event) use(&$calls) { if ($event instanceof \DummyEvent) { $event->calls[] = 'C'; } }); $listeners[] = new AnonymousListener(function (Event $event) use(&$calls) { if ($event instanceof \DummyEvent) { $event->calls[] = 'D'; } }); $listeners[] = new AnonymousListener(function (Event $event) use(&$calls) { if ($event instanceof \DummyEvent) { $event->calls[] = 'E'; } }); $listeners[] = new AnonymousListener(function (Event $event) use(&$calls) { if ($event instanceof \DummyEvent) { $event->calls[] = 'F'; } }); $listeners[] = new AnonymousListener(function (Event $event) use(&$calls) { if ($event instanceof \DummyEvent) { $event->calls[] = 'G'; } }); $listeners[] = new AnonymousListener(function (Event $event) use(&$calls) { if ($event instanceof \DummyEvent) { $event->calls[] = 'H'; } }); $em->add($listeners[3], Priority::HIGHEST); // D $em->add($listeners[4], Priority::HIGHER); // E $em->add($listeners[1], Priority::HIGH); // B $em->add($listeners[7], Priority::NORMAL); // H $em->add($listeners[2], Priority::LOW); // C $em->add($listeners[5], Priority::LOWER); // F $em->add($listeners[6], Priority::LOWEST); // G $em->add($listeners[0], Priority::MONITOR); // A $em->emit($event); $expected = array('D', 'E', 'B', 'H', 'C', 'F', 'G', 'A'); $this->assertEquals($expected, $event->calls); }