Example #1
0
 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());
 }
Example #2
0
 /**
  * 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;
         }
     }
 }