Example #1
0
 /**
  * Trigger event, call listeners
  *
  * @access public
  * @return Event
  */
 public function trigger()
 {
     if ($this->has($this->event->getMethod(), $this->event->getType())) {
         $data =& $this->on[$this->event->getMethod()][$this->event->getType()];
         krsort($data);
         foreach ($data as $items) {
             foreach ($items as $priority => $action) {
                 if (!$this->event->isPropagationStopped()) {
                     $this->call($action);
                 }
             }
         }
     }
     return $this->event;
 }
Example #2
0
 public function broadcast(Event $event)
 {
     $name = $event->getName();
     if (!isset($this->listeners[$name])) {
         return;
     }
     foreach ($this->listeners[$name] as $listener) {
         if ($event->isPropagationStopped()) {
             break;
         }
         $listener->fire($event);
     }
 }
Example #3
0
 /**
  * 触发事件
  * @param string $eventName
  * @param Event $event
  */
 function dispatch($eventName, Event $event = null)
 {
     if (is_null($event)) {
         $event = new Event($eventName, null);
     }
     if (!empty($this->listeners[$eventName])) {
         foreach ($this->listeners[$eventName] as $listener) {
             if ($event->isPropagationStopped()) {
                 break;
             }
             call_user_func([$listener, 'handle'], $event);
         }
     }
 }
Example #4
0
 /**
  * @covers Phossa\Event\Event::isPropagationStopped
  */
 public function testIsPropagationStopped()
 {
     $this->assertTrue(false === $this->object->isPropagationStopped());
     $this->object->stopPropagation();
     $this->assertTrue(true === $this->object->isPropagationStopped());
 }
Example #5
0
 /**
  * Triggers the listeners of an event.
  *
  * This method can be overridden to add functionality that is executed
  * for each listener.
  *
  * @param callable[] $listeners The event listeners.
  * @param string     $eventName The name of the event to dispatch.
  * @param Event      $event     The event object to pass to the event handlers/listeners.
  */
 protected function doDispatch($listeners, $eventName, Event $event)
 {
     foreach ($listeners as $listener) {
         if ($event->isPropagationStopped()) {
             break;
         }
         call_user_func($listener, $event, $eventName, $this);
     }
 }
Example #6
0
 public function testShouldBeAbleToStoppedPropagation()
 {
     $event = new Event('whatever');
     $event->stopPropagation();
     $this->assertTrue($event->isPropagationStopped());
 }
Example #7
0
 /**
  */
 public function testIsPropagationStopped()
 {
     $event = new Event();
     $event->stopPropagation();
     $this->assertEquals(true, $event->isPropagationStopped());
 }