Permalink
Browse files

fix issues #2897

  • Loading branch information...
1 parent 0f584c0 commit 9d4f3e92abde85b5ba229f31998a5fcaa900b8ab @zoghal zoghal committed Feb 26, 2014
Showing with 16 additions and 19 deletions.
  1. +16 −19 lib/Cake/Event/CakeEventManager.php
@@ -259,30 +259,27 @@ public function dispatch($event) {
* @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;
}

0 comments on commit 9d4f3e9

Please sign in to comment.