Found a solution looking at class DefaultResponseParser
:
$command->getRequest()->getResponse();
Is the correct way to accessing the response object. Quite confusing indeed.
Вопрос
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.
Решение
Found a solution looking at class DefaultResponseParser
:
$command->getRequest()->getResponse();
Is the correct way to accessing the response object. Quite confusing indeed.