Ejemplo n.º 1
0
 public function testListenerAttached()
 {
     $events = new EventManager();
     $events->attach($this->listener);
     $listeners = $events->getListeners(MvcEvent::EVENT_DISPATCH_ERROR);
     $this->assertEquals(1, count($listeners));
     $listeners = $events->getListeners(MvcEvent::EVENT_RENDER_ERROR);
     $this->assertEquals(1, count($listeners));
     $events->detach($this->listener);
     $listeners = $events->getListeners(MvcEvent::EVENT_DISPATCH_ERROR);
     $this->assertEquals(0, count($listeners));
     $listeners = $events->getListeners(MvcEvent::EVENT_RENDER_ERROR);
     $this->assertEquals(0, count($listeners));
 }
 /**
  * {@inheritDoc}
  */
 public function removeListener($eventName, $listener)
 {
     $listeners = $this->eventManager->getListeners($eventName);
     foreach ($listeners as $callbackHanler) {
         $callback = $callbackHanler->getCallback();
         if (is_array($callback)) {
             if (is_array($listener)) {
                 if ($callback[0] === $listener[0] && $callback[1] === $listener[1]) {
                     return $this->eventManager->detach($callbackHanler);
                 }
             } else {
                 continue;
             }
         }
         if ($callback === $listener) {
             return $this->eventManager->detach($callbackHanler);
         }
     }
     return true;
 }
Ejemplo n.º 3
0
 public function index08Action()
 {
     $eventManagerOne = new \Zend\EventManager\EventManager();
     $listener1 = $eventManagerOne->attach("eventOne", function ($e) {
         echo "<h3 style='color:red;font-weight:bold'>eventManagerOne - eventOne - Do 1</h3>";
         $e->stopPropagation(true);
     });
     $listener2 = $eventManagerOne->attach("eventOne", function ($e) {
         echo "<h3 style='color:red;font-weight:bold'>eventManagerOne - eventOne - Do 2</h3>";
     });
     $listener3 = $eventManagerOne->attach("eventOne", function ($e) {
         echo "<h3 style='color:red;font-weight:bold'>eventManagerOne - eventOne - Do 3</h3>";
     });
     $eventManagerOne->detach($listener1);
     $eventManagerOne->trigger("eventOne");
     return false;
 }
 public function testAttachAndDetachListener()
 {
     $events = new EventManager();
     $events->attach($this->listener);
     $listeners = $events->getListeners(MvcEvent::EVENT_FINISH);
     $this->assertEquals(1, count($listeners));
     $events->detach($this->listener);
     $listeners = $events->getListeners(MvcEvent::EVENT_FINISH);
     $this->assertEquals(0, count($listeners));
 }