public function testStopPropagation() { $em = new EventManager(); $instanceOne = new StopPropagationListener(); $instanceTwo = new StopPropagationListener(); $em->addListeners('stopPropagationEvent', array(array($instanceOne, 'listener'), array($instanceTwo, 'listener'))); $event = new Event(); $this->assertFalse($event->propagationHalted()); $em->dispatch('stopPropagationEvent', $event); $this->assertTrue($instanceOne->listenerCalled); $this->assertFalse($instanceTwo->listenerCalled); $this->assertTrue($event->propagationHalted()); }
/** * * @param \BedRest\Events\Event $event * * @Events\Listener(event="stopPropagationEvent") */ public function listener(Event $event) { $event->stopPropagation(); $this->listenerCalled = true; }
/** * Dispatches an event to all listeners. * * @param string $event * @param \BedRest\Events\Event $eventObject */ public function dispatch($event, Event $eventObject) { if (!isset($this->listeners[$event])) { return; } foreach ($this->listeners[$event] as $listener) { call_user_func_array($listener, array($eventObject)); if ($eventObject->propagationHalted()) { break; } } }