当前位置: 首页>>代码示例>>PHP>>正文


PHP SharedEventManagerInterface::getListeners方法代码示例

本文整理汇总了PHP中Zend\EventManager\SharedEventManagerInterface::getListeners方法的典型用法代码示例。如果您正苦于以下问题:PHP SharedEventManagerInterface::getListeners方法的具体用法?PHP SharedEventManagerInterface::getListeners怎么用?PHP SharedEventManagerInterface::getListeners使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\EventManager\SharedEventManagerInterface的用法示例。


在下文中一共展示了SharedEventManagerInterface::getListeners方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getListenersByEventName

 /**
  * Get listeners for the currently triggered event.
  *
  * @param  string $eventName
  * @return callable[]
  */
 private function getListenersByEventName($eventName)
 {
     $listeners = array_merge_recursive(isset($this->events[$eventName]) ? $this->events[$eventName] : [], isset($this->events['*']) ? $this->events['*'] : [], $this->sharedManager ? $this->sharedManager->getListeners($this->identifiers, $eventName) : []);
     krsort($listeners, SORT_NUMERIC);
     $listenersForEvent = [];
     foreach ($listeners as $priority => $listenersByPriority) {
         foreach ($listenersByPriority as $listener) {
             // Performance note: after some testing, it appears that accumulating listeners and sending
             // them at the end of the method is FASTER than using generators (ie. yielding)
             $listenersForEvent[] = $listener;
         }
     }
     return $listenersForEvent;
 }
开发者ID:John-Eddy,项目名称:ProjetCastor,代码行数:20,代码来源:EventManager.php

示例2: detachProblemListeners

 /**
  * Detach problem listeners specified by getListenersToDetach() and return an array of information that will
  * allow them to be reattached.
  *
  * @param  SharedEvents $sharedEvents Shared event manager
  * @return array
  */
 protected function detachProblemListeners(SharedEvents $sharedEvents)
 {
     // Convert the problem list from two-dimensional array to more convenient id => event => class format:
     $formattedProblems = array();
     foreach ($this->getListenersToDetach() as $current) {
         if (!isset($formattedProblems[$current['id']])) {
             $formattedProblems[$current['id']] = array();
         }
         if (!isset($formattedProblems[$current['id']][$current['event']])) {
             $formattedProblems[$current['id']][$current['event']] = array();
         }
         $formattedProblems[$current['id']][$current['event']][] = $current['class'];
     }
     // Loop through the class blacklist, detaching problem events and remembering their CallbackHandlers
     // for future reference:
     $results = array();
     foreach ($formattedProblems as $id => $eventArray) {
         $results[$id] = array();
         foreach ($eventArray as $eventName => $classArray) {
             $results[$id][$eventName] = array();
             $events = $sharedEvents->getListeners($id, $eventName);
             foreach ($events as $currentEvent) {
                 $currentCallback = $currentEvent->getCallback();
                 if (!isset($currentCallback[0])) {
                     continue;
                 }
                 foreach ($classArray as $class) {
                     if (is_a($currentCallback[0], $class)) {
                         $sharedEvents->detach($id, $currentEvent);
                         $results[$id][$eventName][] = $currentEvent;
                     }
                 }
             }
         }
     }
     return $results;
 }
开发者ID:leonardovn86,项目名称:zf2_basic2013,代码行数:44,代码来源:Forward.php

示例3: detachProblemListeners

 /**
  * Detach problem listeners specified by getListenersToDetach() and return an array of information that will
  * allow them to be reattached.
  *
  * @param  SharedEvents $sharedEvents Shared event manager
  * @return array
  */
 protected function detachProblemListeners(SharedEvents $sharedEvents)
 {
     // Convert the problem list from two-dimensional array to more convenient id => event => class format:
     $formattedProblems = [];
     foreach ($this->getListenersToDetach() as $current) {
         if (!isset($formattedProblems[$current['id']])) {
             $formattedProblems[$current['id']] = [];
         }
         if (!isset($formattedProblems[$current['id']][$current['event']])) {
             $formattedProblems[$current['id']][$current['event']] = [];
         }
         $formattedProblems[$current['id']][$current['event']][] = $current['class'];
     }
     // Loop through the class blacklist, detaching problem events and remembering their CallbackHandlers
     // for future reference:
     $results = [];
     foreach ($formattedProblems as $id => $eventArray) {
         $results[$id] = [];
         foreach ($eventArray as $eventName => $classArray) {
             $results[$id][$eventName] = [];
             $events = $sharedEvents->getListeners($id, $eventName);
             foreach ($events as $currentEvent) {
                 $currentCallback = $currentEvent->getCallback();
                 // If we have an array, grab the object
                 if (is_array($currentCallback)) {
                     $currentCallback = array_shift($currentCallback);
                 }
                 // This routine is only valid for object callbacks
                 if (!is_object($currentCallback)) {
                     continue;
                 }
                 foreach ($classArray as $class) {
                     if ($currentCallback instanceof $class) {
                         $sharedEvents->detach($id, $currentEvent);
                         $results[$id][$eventName][] = $currentEvent;
                     }
                 }
             }
         }
     }
     return $results;
 }
开发者ID:CHRISTOPHERVANDOMME,项目名称:zf2complet,代码行数:49,代码来源:Forward.php


注:本文中的Zend\EventManager\SharedEventManagerInterface::getListeners方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。