From 9d4f3e92abde85b5ba229f31998a5fcaa900b8ab Mon Sep 17 00:00:00 2001 From: Saleh Souzanchi Date: Wed, 26 Feb 2014 08:02:21 +0330 Subject: [PATCH] fix issues #2897 --- lib/Cake/Event/CakeEventManager.php | 35 +++++++++++++---------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/lib/Cake/Event/CakeEventManager.php b/lib/Cake/Event/CakeEventManager.php index 84fe5f910..0a5a94e7c 100644 --- a/lib/Cake/Event/CakeEventManager.php +++ b/lib/Cake/Event/CakeEventManager.php @@ -259,30 +259,27 @@ class CakeEventManager { * @return array */ public function listeners($eventKey) { + $localListeners = array(); + $priorities = array(); if (!$this->_isGlobal) { - $globalListeners = self::instance()->prioritisedListeners($eventKey); - } else { - $globalListeners = $this->prioritisedListeners($eventKey); + $localListeners = $this->prioritisedListeners($eventKey); + $localListeners = empty($localListeners) ? array() : $localListeners; } - $listeners = array_merge($this->_listeners, self::instance()->_listeners); + $globalListeners = self::instance()->prioritisedListeners($eventKey); + $globalListeners = empty($globalListeners) ? array() : $globalListeners; - if (empty($listeners[$eventKey]) && empty($globalListeners)) { - return array(); - } + $priorities = array_merge(array_keys($globalListeners), array_keys($localListeners)); + $priorities = array_unique($priorities); + asort($priorities); - $listeners = $listeners[$eventKey]; - foreach ($globalListeners as $priority => $priorityQ) { - if (!empty($listeners[$priority])) { - $listeners[$priority] = array_merge($priorityQ, $listeners[$priority]); - unset($globalListeners[$priority]); - } - } - $listeners = $listeners + $globalListeners; - - ksort($listeners); $result = array(); - foreach ($listeners as $priorityQ) { - $result = array_merge($result, $priorityQ); + foreach ($priorities as $priority) { + if (isset($globalListeners[$priority])) { + $result = array_merge($result, $globalListeners[$priority]); + } + if (isset($localListeners[$priority])) { + $result = array_merge($result, $localListeners[$priority]); + } } return $result; }