Problem with Forward Plugin #5432

Merged
merged 5 commits into from Nov 12, 2013

Conversation

Projects
None yet
2 participants
Contributor

weierophinney commented Nov 11, 2013

Hi!

I'm playing with apigility and trying to use it with one of my project. But when i try to login in the system i receive the error:

Fatal error: Cannot use object of type ZF\ContentNegotiation\AcceptListener as array in xxx/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/Plugin/Forward.php on line 179

the error occurs inside detachProblemListeners.

If i comment the attacing listener inside the onBootstrap (zfcampus/zf-content-negotiation/src/ZF/ContentNegotiation/Module.php:122) i can login but the api stops working (as expected).

Maybe Forward.php should check if the callback is in fact an array on line 179 (ZF2 2.2.5)? Something like:

if (!is_array($currentCallback) || !isset($currentCallback[0])) {

Thanks,
Leandro Silva

weierophinney added some commits Nov 11, 2013

@weierophinney weierophinney [#5432] Test if callback is an array prior to accessing as array
- Callbacks can be strings, objects (functors), or closures, too.
- Allow testing against functor callbacks
b91c76f
@weierophinney weierophinney [#5432] Added test
- Finally determined a way to add a test for this.
e5fd6bf
@weierophinney weierophinney [#5432] CS fixes
- Trailing whitespace
9c5ba9b
Owner

weierophinney commented Nov 11, 2013

I've added code that does the following:

  • Tests if we have either an object or an array callback, returning early if not.
  • Allows testing either an object or array callback against the blacklist (as the former likely should be tested).

The test added did indeed display an error before the fix, and now does not.

@Maks3w Maks3w and 1 other commented on an outdated diff Nov 12, 2013

library/Zend/Mvc/Controller/Plugin/Forward.php
@@ -176,11 +176,22 @@ protected function detachProblemListeners(SharedEvents $sharedEvents)
$events = $sharedEvents->getListeners($id, $eventName);
foreach ($events as $currentEvent) {
$currentCallback = $currentEvent->getCallback();
- if (!isset($currentCallback[0])) {
+
+ // Testing against object callbacks
@Maks3w

Maks3w Nov 12, 2013

Member

What do you think about rewrite this part with this?

if (is_array($currentCallback)) {
    $currentCallback = array_shift($currentCallback);
}

if (!is_object($currentCallback) {
    continue;
}
@weierophinney

weierophinney Nov 12, 2013

Owner

Sounds good! Implementing now.

Maks3w was assigned Nov 12, 2013

@Maks3w Maks3w added a commit that referenced this pull request Nov 12, 2013

@Maks3w Maks3w Merge pull request #5432 5b60684

@Maks3w Maks3w added a commit that referenced this pull request Nov 12, 2013

@Maks3w Maks3w Merge pull request #5432 in develop 883b818

@Maks3w Maks3w added a commit that referenced this pull request Nov 12, 2013

@Maks3w Maks3w Merge pull request #5432 in master d960a5e

@Maks3w Maks3w merged commit 2c20e80 into zendframework:master Nov 12, 2013

1 check passed

default The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment