本文整理汇总了PHP中GuzzleHttp\Message\ResponseInterface::getHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP ResponseInterface::getHeaders方法的具体用法?PHP ResponseInterface::getHeaders怎么用?PHP ResponseInterface::getHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Message\ResponseInterface
的用法示例。
在下文中一共展示了ResponseInterface::getHeaders方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isError
protected function isError(ResponseInterface $response)
{
if (\array_get($response->getHeaders(), 'RETS-Error', [null])[0] == 1) {
return true;
}
$content_type = \array_get($response->getHeaders(), 'Content-Type', [null])[0];
if ($content_type and strpos($content_type, 'xml') !== false) {
return true;
}
return false;
}
示例2: _getResult
/**
* @param ResponseInterface $response
*
* @return ApiResult
*/
protected function _getResult($response)
{
if (!$response instanceof ResponseInterface) {
throw new \InvalidArgumentException("{$response} should be an instance of ResponseInterface");
}
$result = new ApiResult();
$result->setStatusCode($response->getStatusCode());
$callId = $response->getHeader('X-Call-Id');
if (!empty($callId)) {
$result->setCallId($callId);
}
$decoded = json_decode((string) $response->getBody());
if (isset($decoded->meta) && isset($decoded->data) && isset($decoded->meta->code) && $decoded->meta->code == $response->getStatusCode()) {
$meta = $decoded->meta;
$data = $decoded->data;
if (isset($meta->message)) {
$result->setStatusMessage($meta->message);
}
$result->setContent(json_encode($data));
} else {
$result->setContent((string) $response->getBody());
}
$result->setHeaders($response->getHeaders());
return $result;
}
示例3: formatHeaders
/**
* @param RequestInterface|ResponseInterface $message
* @return string
*/
protected function formatHeaders($message)
{
$headers = [];
foreach ($message->getHeaders() as $header => $value) {
$headers[] = sprintf('%s: %s', $header, implode("\n : ", $value));
}
return implode("\n", $headers);
}
示例4: getHeadersAsString
/**
* Returns the Guzzle array of headers as a string.
*
* @param ResponseInterface $response The Guzzle response.
*
* @return string
*/
public function getHeadersAsString(ResponseInterface $response)
{
$headers = $response->getHeaders();
$rawHeaders = [];
foreach ($headers as $name => $values) {
$rawHeaders[] = $name . ": " . implode(", ", $values);
}
return implode("\r\n", $rawHeaders);
}
示例5: createResponse
/**
* Create the response object
*
* @param ResponseInterface $adapterResponse
* @return \Tmdb\HttpClient\Response
*/
private function createResponse(ResponseInterface $adapterResponse = null)
{
$response = new Response();
if ($adapterResponse !== null) {
$response->setCode($adapterResponse->getStatusCode());
$response->setHeaders(new ParameterBag($adapterResponse->getHeaders()));
$response->setBody((string) $adapterResponse->getBody());
}
return $response;
}
示例6: save
public function save(RequestInterface $request, ResponseInterface $response)
{
$ttl = (int) $request->getConfig()->get('cache.ttl');
$key = $this->getCacheKey($request);
// Persist the response body if needed
if ($response->getBody() && $response->getBody()->getSize() > 0) {
$this->cache->save($key, array('code' => $response->getStatusCode(), 'headers' => $response->getHeaders(), 'body' => (string) $response->getBody()), $ttl);
$request->getConfig()->set('cache.key', $key);
}
}
示例7: parseMetadata
public function parseMetadata(ResponseInterface $response)
{
$metadata = [];
foreach ($response->getHeaders() as $header => $value) {
$position = strpos($header, static::METADATA_PREFIX);
if ($position === 0) {
$metadata[ltrim($header, static::METADATA_PREFIX)] = $response->getHeader($header);
}
}
return $metadata;
}
示例8: assertResponseMatch
/**
* Asserts response match with the response schema.
*
* @param ResponseInterface $response
* @param SchemaManager $schemaManager
* @param string $path percent-encoded path used on the request.
* @param string $httpMethod
* @param string $message
*/
public function assertResponseMatch(ResponseInterface $response, SchemaManager $schemaManager, $path, $httpMethod, $message = '')
{
$this->assertResponseMediaTypeMatch($response->getHeader('Content-Type'), $schemaManager, $path, $httpMethod, $message);
$httpCode = $response->getStatusCode();
$headers = $response->getHeaders();
foreach ($headers as &$value) {
$value = implode(', ', $value);
}
$this->assertResponseHeadersMatch($headers, $schemaManager, $path, $httpMethod, $httpCode, $message);
$this->assertResponseBodyMatch($response->json(['object' => true]), $schemaManager, $path, $httpMethod, $httpCode, $message);
}
示例9: extractHeaders
/**
* Extract a map of headers with an optional prefix from the response.
*/
private function extractHeaders($name, Shape $shape, ResponseInterface $response, &$result)
{
// Check if the headers are prefixed by a location name
$result[$name] = [];
$prefix = $shape['locationName'];
$prefixLen = strlen($prefix);
foreach ($response->getHeaders() as $k => $values) {
if (!$prefixLen) {
$result[$name][$k] = implode(', ', $values);
} elseif (stripos($k, $prefix) === 0) {
$result[$name][substr($k, $prefixLen)] = implode(', ', $values);
}
}
}
示例10: validateResponse
/**
* Validate the response.
*
* @return $this
*/
protected function validateResponse()
{
$body = $this->request->getBody();
$this->response = $body->getContents();
// Send new request
if ($this->request == false || $this->request->getReasonPhrase() != 'OK') {
$this->objDebug->addDebug("Request", substr($this->response, 0, 4096));
$this->objDebug->addDebug("Error Response", substr($this->response, 0, 4096));
throw new \RuntimeException("Error on transmission, with message: " . $this->request->getStatusCode());
}
$this->objDebug->addDebug("Request", substr($this->response, 0, 4096));
// Build response Header information.
$strResponseHeader = "";
$arrHeaderKeys = array_keys($this->request->getHeaders());
foreach ($arrHeaderKeys as $keyHeader) {
$strResponseHeader .= $keyHeader . ": " . $this->request->getHeader($keyHeader) . "\n";
}
$this->objDebug->addDebug("Response", $strResponseHeader . "\n\n" . $this->request->getBody()->read(2048));
// Check if we have a response
if (strlen($this->response) == 0) {
throw new \RuntimeException("We got a blank response from server.");
}
// Check for "Fatal error" on client side
if (strpos($this->response, "Fatal error") !== false) {
throw new \RuntimeException("We got a Fatal error on client site. " . $this->response);
}
// Check for "Warning" on client side
if (strpos($this->response, "Warning") !== false) {
$intStart = stripos($this->response, "<strong>Warning</strong>:");
$intEnd = stripos($this->response, "on line");
if ($intEnd === false) {
$intLength = strlen($this->response) - $intStart;
} else {
$intLength = $intEnd - $intStart;
}
throw new \RuntimeException("We got a Warning on client site.<br /><br />" . substr($this->response, $intStart, $intLength));
}
return $this;
}
示例11: headers
/**
* @return array
*/
public function headers()
{
return $this->response->getHeaders();
}
示例12: convertResponse
/**
* Conver the Guzzle response to a Symfony response.
*
* @param ResponseInterface $response
* @return Response
*/
protected function convertResponse(ResponseInterface $response)
{
return new Response($response->getBody(), $response->getStatusCode(), $response->getHeaders());
}
示例13: getBodyContent
/**
* @param \GuzzleHttp\Message\ResponseInterface $response
*
* @return array
*/
protected function getBodyContent(ResponseInterface $response)
{
$body = $response->getBody();
$headers = $response->getHeaders();
return $this->createContent($headers, $body);
}
示例14: __construct
public function __construct(HttpResponseInterface $response)
{
$this->_statusCode = $response->getStatusCode();
$this->_headers = $response->getHeaders();
$this->_body = $response->json();
}
示例15: createResponse
/**
* Converts a Guzzle response into a PSR response.
*
* @param GuzzleResponse $response
*
* @return ResponseInterface
*/
private function createResponse(GuzzleResponse $response)
{
$body = $response->getBody();
return $this->messageFactory->createResponse($response->getStatusCode(), null, $response->getHeaders(), isset($body) ? $body->detach() : null, $response->getProtocolVersion());
}