當前位置: 首頁>>代碼示例>>PHP>>正文


PHP EventManager::detach方法代碼示例

本文整理匯總了PHP中Zend\EventManager\EventManager::detach方法的典型用法代碼示例。如果您正苦於以下問題:PHP EventManager::detach方法的具體用法?PHP EventManager::detach怎麽用?PHP EventManager::detach使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend\EventManager\EventManager的用法示例。


在下文中一共展示了EventManager::detach方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testListenerAttached

 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));
 }
開發者ID:simplicity-ag,項目名稱:NewRelic,代碼行數:14,代碼來源:ErrorListenerTest.php

示例2: removeListener

 /**
  * {@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;
 }
開發者ID:malocher,項目名稱:zf2-event-store-module,代碼行數:23,代碼來源:EventManagerProxy.php

示例3: index08Action

 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;
 }
開發者ID:trongle,項目名稱:zend-2,代碼行數:17,代碼來源:EventController.php

示例4: testAttachAndDetachListener

 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));
 }
開發者ID:simplicity-ag,項目名稱:NewRelic,代碼行數:10,代碼來源:ResponseListenerTest.php


注:本文中的Zend\EventManager\EventManager::detach方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。