コード例 #1
0
ファイル: DispatchTest.php プロジェクト: bedrest/events
 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());
 }
コード例 #2
0
 /**
  * 
  * @param \BedRest\Events\Event $event
  * 
  * @Events\Listener(event="stopPropagationEvent")
  */
 public function listener(Event $event)
 {
     $event->stopPropagation();
     $this->listenerCalled = true;
 }
コード例 #3
0
ファイル: EventManager.php プロジェクト: bedrest/events
 /**
  * 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;
         }
     }
 }