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

Problem with Forward Plugin #5432

Merged
merged 5 commits into from
Nov 12, 2013
Merged

Conversation

weierophinney
Copy link
Member

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

…as array

- Callbacks can be strings, objects (functors), or closures, too.
- Allow testing against functor callbacks
- Finally determined a way to add a test for this.
- Trailing whitespace
@weierophinney
Copy link
Member

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.

@@ -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
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about rewrite this part with this?

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

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good! Implementing now.

@ghost ghost assigned Maks3w Nov 12, 2013
Maks3w added a commit that referenced this pull request Nov 12, 2013
Maks3w added a commit that referenced this pull request Nov 12, 2013
Maks3w added a commit that referenced this pull request Nov 12, 2013
@Maks3w Maks3w merged commit 2c20e80 into zendframework:master Nov 12, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants