0

My very basic understanding of Guzzle internals maybe the cause of this error (PHPUnit test):

PHP Fatal error: Maximum function nesting level of '100' reached, aborting! in \vendor\guzzle\guzzle\src\Guzzle\Http\QueryString.php on line 234

It seems that the following sections (plugin and parser) are calling each other. The plugin is listening for command.before_send event, adding a closure as listener for the request.exception event:

/**
 * The plugin adds a closure listener for the event 'response.exception'. The
 * closure is using the parser (RestInterfaceParser).
 */
class ResponseListener implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return array('command.before_send' => 'onCommandBeforeSend');
    }

    public function onCommandBeforeSend(Event $event)
    {
        // ...
        $command = $event['command'];
        $request = $command->getRequest();

        $request->getEventDispatcher()->addListener(
            'request.exception',
            function (Event $event) use ($command, $parser) {
                $parsed = $parser->parse($command);

                // ...
            }
        );
    }
}

Nothing special so far! The error is caused by the parser, when I try to access the response object:

/**
 * The parser invoked by the closure listener.
 */
class RestInterfaceParser implements ResponseParserInterface
{
    public function parse(CommandInterface $command)
    {
        var_dump($command->getResponse());
    }
}

Removing that line removes the error. But, big surprise, I need the response object inside the parser. Increasing the nesting level (xdebug.max_nesting_level = 1000) doesn't help because it's "pure" recursion here.

2
  • Are you sure you are dealing exactly with the object you are expecting? Dump the object, not only the result of getResponse(). And do more debugging. The problem with understanding your question is that there is much more going on in code we do not see. And actually I have NO idea where the interfaces and classes do come from that you use. Commented Jul 17, 2013 at 13:02
  • @Sven I've found a solution (I've already posted the answer)... and yes, I was NOT dealing with the command object properly. Commented Jul 17, 2013 at 13:09

1 Answer 1

0

Found a solution looking at class DefaultResponseParser:

$command->getRequest()->getResponse();

Is the correct way to accessing the response object. Quite confusing indeed.

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, this will work. The reason you are seeing infinite recursion is because a response is only set on a command object when a request succeeds. Otherwise, it attempts to send the request again. You can also use the response context value of the Event that is emitted by the request.exception event.
@MichaelDowling thank you for confirming this. Mind if I ask you to help with this question? stackoverflow.com/questions/17705907/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.