本文整理汇总了PHP中GuzzleHttp\Message\Response::setHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setHeaders方法的具体用法?PHP Response::setHeaders怎么用?PHP Response::setHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Message\Response
的用法示例。
在下文中一共展示了Response::setHeaders方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMock
/**
* Getting Guzzle mock response.
*
* @param string $requestUrl Full API endpoint URL
* @param mixed $requestBody Request body.
*
* @return Mock Guzzle mock response.
*/
private function getMock($requestUrl, $requestBody)
{
if (!is_string($requestBody)) {
$requestBody = print_r($requestBody, true);
}
$filename = self::$settings->mockResponsesDir . md5($requestUrl) . md5($requestBody) . '.inc';
if (file_exists($filename)) {
$data = null;
require $filename;
$data['headers'] = (array) json_decode(htmlspecialchars_decode($data['headers_json'], ENT_QUOTES));
$mockResponse = new Response($data['httpCode']);
$mockResponse->setHeaders($data['headers']);
$separator = "\r\n\r\n";
$bodyParts = explode($separator, htmlspecialchars_decode($data['response']), ENT_QUOTES);
if (count($bodyParts) > 1) {
$mockResponse->setBody(Stream::factory($bodyParts[count($bodyParts) - 1]));
} else {
$mockResponse->setBody(Stream::factory(htmlspecialchars_decode($data['response'])));
}
$mock = new Mock([$mockResponse]);
} else {
$mockResponse = new Response(404);
$mock = new Mock([$mockResponse]);
}
return $mock;
}