尝试调用 Response->getInfo() 失败,即使它存在于 API 中


Trying to call Response->getInfo() fails even though it exist in the API

我正在尝试使用Guzzle(~5.0)来获得相当于php curl_getinfo。api说它在这里存在,但是在进行调用时,我收到一个错误,说:

调用未定义的方法 GuzzleHttp''Message''Response::getInfo() in ...

我可以getBody()getStatusCode()和许多其他功能Response,但getInfo()不起作用。它已被弃用吗?这是一个错误吗?我打错电话了吗?

use GuzzleHttp'Client;
use GuzzleHttp'Message'Response;
class GuzzleCommand extends Command {
    public function fire()
    {
        $client = new Client();
        //equivalent of echo:
        $this->info($client->get('http://google.com')->getInfo());
    }
}

您正在阅读已弃用的 API,如此问题中所述,使用 getInfo() 方法,此问题涉及 API 版本以及自 v4.x 起的这些升级文档:

GuzzleHttp'Message'Response::getInfo()GuzzleHttp'Message'Response::setInfo()已被移除。使用事件系统检索此类信息。

有关事件系统的文档,请参见此处。