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

Fix for Forward in zend-eventmanager v3 #112

Merged
merged 3 commits into from
Apr 6, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 29 additions & 22 deletions src/Controller/Plugin/Forward.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [$currentPriorityEvents];
}
// v3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment can be removed, as the logic below executes for either version. (I'll do that during merge.)

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;
}
}
}
}
Expand Down