@@ -179,32 +179,39 @@ protected function detachProblemListeners(SharedEvents $sharedEvents)
179
179
foreach ($ eventArray as $ eventName => $ classArray ) {
180
180
$ results [$ id ][$ eventName ] = [];
181
181
$ 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 ];
189
186
}
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
+ }
190
196
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
+ }
195
201
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
+ }
200
206
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
+ }
208
215
}
209
216
}
210
217
}
0 commit comments