我对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.