Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 4f5aa15

Browse files
committed
Merge branch 'hotfix/112' into develop
Forward port #112
2 parents 9eac40b + 1085114 commit 4f5aa15

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

Diff for: CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ for full details on how to migrate your v2 application.
117117
- [#107](https://github.com/zendframework/zend-mvc/pull/107) fixes an incorrect
118118
import statement in the `DiStrictAbstractServiceFactoryFactory` that prevented
119119
it from working.
120+
- [#112](https://github.com/zendframework/zend-mvc/pull/112) fixes how the
121+
`Forward` plugin detects and detaches event listeners to ensure it works
122+
against either v2 or v3 releases of zend-eventmanager.
120123

121124
## 2.7.5 - 2016-04-06
122125

Diff for: src/Controller/Plugin/Forward.php

+29-22
Original file line numberDiff line numberDiff line change
@@ -179,32 +179,39 @@ protected function detachProblemListeners(SharedEvents $sharedEvents)
179179
foreach ($eventArray as $eventName => $classArray) {
180180
$results[$id][$eventName] = [];
181181
$events = $this->getSharedListenersById($id, $eventName, $sharedEvents);
182-
foreach ($events as $priority => $currentEvent) {
183-
$currentCallback = $currentEvent;
184-
185-
// zend-eventmanager v2 compatibility:
186-
if ($currentCallback instanceof CallbackHandler) {
187-
$currentCallback = $currentEvent->getCallback();
188-
$priority = $currentEvent->getMetadatum('priority');
182+
foreach ($events as $priority => $currentPriorityEvents) {
183+
// v2 fix
184+
if (!is_array($currentPriorityEvents)) {
185+
$currentPriorityEvents = [$currentPriorityEvents];
189186
}
187+
// v3
188+
foreach ($currentPriorityEvents as $currentEvent) {
189+
$currentCallback = $currentEvent;
190+
191+
// zend-eventmanager v2 compatibility:
192+
if ($currentCallback instanceof CallbackHandler) {
193+
$currentCallback = $currentEvent->getCallback();
194+
$priority = $currentEvent->getMetadatum('priority');
195+
}
190196

191-
// If we have an array, grab the object
192-
if (is_array($currentCallback)) {
193-
$currentCallback = array_shift($currentCallback);
194-
}
197+
// If we have an array, grab the object
198+
if (is_array($currentCallback)) {
199+
$currentCallback = array_shift($currentCallback);
200+
}
195201

196-
// This routine is only valid for object callbacks
197-
if (!is_object($currentCallback)) {
198-
continue;
199-
}
202+
// This routine is only valid for object callbacks
203+
if (!is_object($currentCallback)) {
204+
continue;
205+
}
200206

201-
foreach ($classArray as $class) {
202-
if ($currentCallback instanceof $class) {
203-
// Pass $currentEvent; when using zend-eventmanager v2,
204-
// this is the CallbackHandler, while in v3 it's
205-
// the actual listener.
206-
$this->detachSharedListener($id, $currentEvent, $sharedEvents);
207-
$results[$id][$eventName][$priority] = $currentEvent;
207+
foreach ($classArray as $class) {
208+
if ($currentCallback instanceof $class) {
209+
// Pass $currentEvent; when using zend-eventmanager v2,
210+
// this is the CallbackHandler, while in v3 it's
211+
// the actual listener.
212+
$this->detachSharedListener($id, $currentEvent, $sharedEvents);
213+
$results[$id][$eventName][$priority] = $currentEvent;
214+
}
208215
}
209216
}
210217
}

0 commit comments

Comments
 (0)