From 4d495c932e4e3cce206899a5e36ce7d2e0951e5e Mon Sep 17 00:00:00 2001 From: Rodrigo Boratto Date: Thu, 31 Mar 2016 15:46:21 -0300 Subject: [PATCH 1/3] Fix for Forward in zend-eventmanager v3 Actually, EventManager returns an ARRAY on `$sharedEvents->getListeners` and the way it was implemented the `listenersToDetach` it wasn't working. I don't know if in V2 it is the same thing, so, this pull request FIX this method and a problem from rendering the View two times. Like this old bug: http://zend-framework-community.634137.n4.nabble.com/Double-rendering-with-forward-plugin-td4656067i20.html Thanks, Rodrigo --- src/Controller/Plugin/Forward.php | 51 ++++++++++++++++++------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/Controller/Plugin/Forward.php b/src/Controller/Plugin/Forward.php index 413341837..5d1be1ded 100644 --- a/src/Controller/Plugin/Forward.php +++ b/src/Controller/Plugin/Forward.php @@ -179,32 +179,39 @@ protected function detachProblemListeners(SharedEvents $sharedEvents) foreach ($eventArray as $eventName => $classArray) { $results[$id][$eventName] = []; $events = $this->getSharedListenersById($id, $eventName, $sharedEvents); - foreach ($events as $priority => $currentEvent) { - $currentCallback = $currentEvent; - - // zend-eventmanager v2 compatibility: - if ($currentCallback instanceof CallbackHandler) { - $currentCallback = $currentEvent->getCallback(); - $priority = $currentEvent->getMetadatum('priority'); + foreach ($events as $priority => $currentPriorityEvents) { + // v2 fix + if (!is_array($currentPriorityEvents)) { + $currentPriorityEvents = array($currentPriorityEvents); } + // v3 + foreach ($currentPriorityEvents as $currentEvent) { + $currentCallback = $currentEvent; + + // zend-eventmanager v2 compatibility: + if ($currentCallback instanceof CallbackHandler) { + $currentCallback = $currentEvent->getCallback(); + $priority = $currentEvent->getMetadatum('priority'); + } - // If we have an array, grab the object - if (is_array($currentCallback)) { - $currentCallback = array_shift($currentCallback); - } + // 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; - } + // This routine is only valid for object callbacks + if (!is_object($currentCallback)) { + continue; + } - foreach ($classArray as $class) { - if ($currentCallback instanceof $class) { - // Pass $currentEvent; when using zend-eventmanager v2, - // this is the CallbackHandler, while in v3 it's - // the actual listener. - $this->detachSharedListener($id, $currentEvent, $sharedEvents); - $results[$id][$eventName][$priority] = $currentEvent; + foreach ($classArray as $class) { + if ($currentCallback instanceof $class) { + // Pass $currentEvent; when using zend-eventmanager v2, + // this is the CallbackHandler, while in v3 it's + // the actual listener. + $this->detachSharedListener($id, $currentEvent, $sharedEvents); + $results[$id][$eventName][$priority] = $currentEvent; + } } } } From eec65d200f50f305d321326b446c59badaa282a1 Mon Sep 17 00:00:00 2001 From: Rodrigo Boratto Date: Fri, 1 Apr 2016 14:58:36 -0300 Subject: [PATCH 2/3] Forcing travis to rebuild - can't find the error --- src/Controller/Plugin/Forward.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Controller/Plugin/Forward.php b/src/Controller/Plugin/Forward.php index 5d1be1ded..d04c1f652 100644 --- a/src/Controller/Plugin/Forward.php +++ b/src/Controller/Plugin/Forward.php @@ -184,6 +184,7 @@ protected function detachProblemListeners(SharedEvents $sharedEvents) if (!is_array($currentPriorityEvents)) { $currentPriorityEvents = array($currentPriorityEvents); } + // v3 foreach ($currentPriorityEvents as $currentEvent) { $currentCallback = $currentEvent; From b60730fc86fce952af4da291b4c603e36c0a57cc Mon Sep 17 00:00:00 2001 From: Rodrigo Boratto Date: Fri, 1 Apr 2016 15:18:31 -0300 Subject: [PATCH 3/3] Trying to pass on php-cs-fixer --- src/Controller/Plugin/Forward.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Controller/Plugin/Forward.php b/src/Controller/Plugin/Forward.php index d04c1f652..41239b92c 100644 --- a/src/Controller/Plugin/Forward.php +++ b/src/Controller/Plugin/Forward.php @@ -182,9 +182,8 @@ protected function detachProblemListeners(SharedEvents $sharedEvents) foreach ($events as $priority => $currentPriorityEvents) { // v2 fix if (!is_array($currentPriorityEvents)) { - $currentPriorityEvents = array($currentPriorityEvents); + $currentPriorityEvents = [$currentPriorityEvents]; } - // v3 foreach ($currentPriorityEvents as $currentEvent) { $currentCallback = $currentEvent;