本文整理汇总了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;
}
示例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;
}
示例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;
}