0

我对Guzzle内部的非常基本的了解可能是导致此错误的原因(PHPUnit 测试):

PHP 致命错误:达到“100”的最大函数嵌套级别,正在中止!在 \vendor\guzzle\guzzle\src\Guzzle\Http\QueryString.php 第 234 行

似乎以下部分(插件和解析器)正在相互调用。该插件正在侦听command.before_send事件,添加一个闭包作为request.exception事件的侦听器:

/**
 * 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);

                // ...
            }
        );
    }
}

到目前为止没有什么特别的!当我尝试访问响应对象时,错误是由解析器引起的:

/**
 * 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.

4

1 回答 1

0

Found a solution looking at class DefaultResponseParser:

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

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

于 2013-07-17T13:01:22.257 回答