当前位置: 首页>>代码示例>>PHP>>正文


PHP ResponseInterface::getHeader方法代码示例

本文整理汇总了PHP中GuzzleHttp\Message\ResponseInterface::getHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP ResponseInterface::getHeader方法的具体用法?PHP ResponseInterface::getHeader怎么用?PHP ResponseInterface::getHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GuzzleHttp\Message\ResponseInterface的用法示例。


在下文中一共展示了ResponseInterface::getHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getLatestResponseHeaders

 /**
  * {@inheritdoc}
  */
 public function getLatestResponseHeaders()
 {
     if (null === $this->response) {
         return;
     }
     return array('reset' => (int) (string) $this->response->getHeader('RateLimit-Reset'), 'remaining' => (int) (string) $this->response->getHeader('RateLimit-Remaining'), 'limit' => (int) (string) $this->response->getHeader('RateLimit-Limit'));
 }
开发者ID:fideloper,项目名称:DigitalOceanV2,代码行数:10,代码来源:Guzzle5Adapter.php

示例2: decode

 public function decode(ResponseInterface $raw, $totalTime = 0)
 {
     $executionTime = $callTime = 0;
     if ($raw->hasHeader('X-Execution-Time')) {
         $executionTime = $raw->getHeader('X-Execution-Time');
     }
     if ($raw->hasHeader('X-Call-Time')) {
         $callTime = $raw->getHeader('X-Call-Time');
     }
     $body = '';
     try {
         $body = (string) $raw->getBody();
         $result = $this->_getDecoder()->decode($body, self::FORMAT, $this->_getDecodeContext());
     } catch (\Exception $e) {
         if (!empty($body)) {
             $body = ' (' . $body . ')';
         }
         error_log("Invalid API Response: " . $body);
         throw new InvalidApiResponseException("Unable to decode raw api response.", 500, $e);
     }
     if (!property_exists($result, 'type') || !property_exists($result, 'status') || !property_exists($result, 'result') || !property_exists($result->status, 'message') || !property_exists($result->status, 'code')) {
         error_log("Invalid API Result: " . json_encode($result));
         throw new InvalidApiResponseException("Invalid api result", 500);
     }
     if ($executionTime === 0) {
         $executionTime = $totalTime;
     }
     if ($callTime === 0) {
         $callTime = $executionTime;
     }
     return ResponseBuilder::create(ApiCallData::create($result->type, $result->result, $result->status->code, $result->status->message, (double) str_replace([',', 'ms'], '', $totalTime), (double) str_replace([',', 'ms'], '', $executionTime), (double) str_replace([',', 'ms'], '', $callTime)));
 }
开发者ID:packaged,项目名称:api,代码行数:32,代码来源:AbstractApiFormat.php

示例3: getResponseAge

 /**
  * Gets the age of a response in seconds.
  *
  * @param ResponseInterface $response
  *
  * @return int
  */
 public static function getResponseAge(ResponseInterface $response)
 {
     if ($response->hasHeader('Age')) {
         return (int) $response->getHeader('Age');
     }
     $date = strtotime($response->getHeader('Date') ?: 'now');
     return time() - $date;
 }
开发者ID:thomaschaaf,项目名称:cache-subscriber,代码行数:15,代码来源:Utils.php

示例4: __construct

 /**
  * @param ResponseInterface $response raw json response
  * @param bool              $throw    Should throw API errors as exceptions
  *
  * @throws \Exception
  */
 public function __construct(ResponseInterface $response = null, $throw = true)
 {
     if ($response !== null) {
         $this->_executionTime = $response->getHeader('X-Execution-Time');
         $this->_callTime = $response->getHeader('X-Call-Time');
         $this->readJson((string) $response->getBody(), $throw);
     }
 }
开发者ID:jdi,项目名称:tntaffiliate,代码行数:14,代码来源:ApiResult.php

示例5: getResponse

 protected function getResponse(GuzzleResponse $response)
 {
     if (strpos($response->getHeader('Content-Type'), 'json')) {
         $returnResponse = new JsonResponse($response->getBody());
     } elseif (strpos($response->getHeader('Content-Type'), 'xml')) {
         $returnResponse = new XmlResponse($response->xml());
     } else {
         throw new \Exception('Unknow return type');
     }
     return $returnResponse;
 }
开发者ID:bxav,项目名称:service_handler,代码行数:11,代码来源:ResellerClubClient.php

示例6: getLocation

 /**
  * Gets the Location header.
  *
  * @throws \RuntimeException If the Location header is missing
  *
  * @return string
  */
 public function getLocation()
 {
     if (!$this->response->hasHeader('Location')) {
         throw new \RuntimeException('Response is missing a Location header');
     }
     return $this->response->getHeader('Location');
 }
开发者ID:sam-akopyan,项目名称:hamradio,代码行数:14,代码来源:ResponseValidator.php

示例7: _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;
 }
开发者ID:fortifi,项目名称:api,代码行数:30,代码来源:Guzzle5Connection.php

示例8:

 function it_should_make_post_request(ResponseInterface $responce)
 {
     $responce->getHeader("Content-Type")->willReturn('blablaxmlblabla');
     $responce->getBody()->willReturn('<xml></xml>');
     $this->client->post(Argument::any(), Argument::any())->willReturn($responce);
     $responce->xml()->willReturn(new \SimpleXMLElement('<xml></xml>'));
     $this->post(Argument::type('string'))->shouldBeAnInstanceOf('Bxav\\Component\\ResellerClub\\Model\\XmlResponse');
 }
开发者ID:bxav,项目名称:service_handler,代码行数:8,代码来源:ResellerClubClientSpec.php

示例9: visit

 public function visit(GuzzleCommandInterface $command, ResponseInterface $response, Parameter $param, &$result, array $context = array())
 {
     // Retrieving a single header by name
     $name = $param->getName();
     if ($header = $response->getHeader($param->getWireName())) {
         $result[$name] = $param->filter($header);
     }
 }
开发者ID:bobozhangshao,项目名称:HeartCare,代码行数:8,代码来源:HeaderLocation.php

示例10: parseHeaders

 private function parseHeaders(ResponseInterface $response, array &$data)
 {
     $data['message'] = $response->getStatusCode() . ' ' . $response->getReasonPhrase();
     if ($requestId = $response->getHeader('x-amz-request-id')) {
         $data['request_id'] = $requestId;
         $data['message'] .= " (Request-ID: {$requestId})";
     }
 }
开发者ID:briareos,项目名称:aws-sdk-php,代码行数:8,代码来源:XmlErrorParser.php

示例11: theResponseHasTheOAuth2Format

 /**
  * @Then the response is oauth2 format
  */
 public function theResponseHasTheOAuth2Format()
 {
     $expectedHeaders = ['cache-control' => 'no-store', 'pragma' => 'no-cache'];
     foreach ($expectedHeaders as $name => $value) {
         if ($this->response->getHeader($name) != $value) {
             throw new \Exception(sprintf("Header %s is should be %s, %s given", $name, $value, $this->response->getHeader($name)));
         }
     }
 }
开发者ID:rstgroup,项目名称:behat-oauth2-context,代码行数:12,代码来源:OAuth2Context.php

示例12: populateFromResponse

 /**
  * Populates the current resource from a response object.
  *
  * @param ResponseInterface $response
  *
  * @return $this|ResourceInterface
  */
 public function populateFromResponse(ResponseInterface $response)
 {
     if (strpos($response->getHeader('Content-Type'), 'application/json') === 0) {
         $json = $response->json();
         if (!empty($json)) {
             $this->populateFromArray($this->flatten($json));
         }
     }
     return $this;
 }
开发者ID:boxrice007,项目名称:openstack,代码行数:17,代码来源:AbstractResource.php

示例13: parse

 public function parse(ResponseInterface $response)
 {
     $collection = new Collection();
     if (!$response->getBody()) {
         return $collection;
     }
     // help bad responses be more multipart compliant
     $body = "\r\n" . $response->getBody()->__toString() . "\r\n";
     // multipart
     preg_match('/boundary\\=\\"(.*?)\\"/', $response->getHeader('Content-Type'), $matches);
     if (isset($matches[1])) {
         $boundary = $matches[1];
     } else {
         preg_match('/boundary\\=(.*?)(\\s|$|\\;)/', $response->getHeader('Content-Type'), $matches);
         $boundary = $matches[1];
     }
     // strip quotes off of the boundary
     $boundary = preg_replace('/^\\"(.*?)\\"$/', '\\1', $boundary);
     // clean up the body to remove a reamble and epilogue
     $body = preg_replace('/^(.*?)\\r\\n--' . $boundary . '\\r\\n/', "\r\n--{$boundary}\r\n", $body);
     // make the last one look like the rest for easier parsing
     $body = preg_replace('/\\r\\n--' . $boundary . '--/', "\r\n--{$boundary}\r\n", $body);
     // cut up the message
     $multi_parts = explode("\r\n--{$boundary}\r\n", $body);
     // take off anything that happens before the first boundary (the preamble)
     array_shift($multi_parts);
     // take off anything after the last boundary (the epilogue)
     array_pop($multi_parts);
     $message_parser = new MessageParser();
     $parser = new Single();
     // go through each part of the multipart message
     foreach ($multi_parts as $part) {
         // get Guzzle to parse this multipart section as if it's a whole HTTP message
         $parts = $message_parser->parseResponse("HTTP/1.1 200 OK\r\n" . $part);
         // now throw this single faked message through the Single GetObject response parser
         $single = new Response($parts['code'], $parts['headers'], Stream::factory($parts['body']));
         $obj = $parser->parse($single);
         // add information about this multipart to the returned collection
         $collection->push($obj);
     }
     return $collection;
 }
开发者ID:mitchlayzell,项目名称:PHRETS,代码行数:42,代码来源:Multiple.php

示例14: 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);
 }
开发者ID:Beanhunter,项目名称:SwaggerAssertions,代码行数:20,代码来源:GuzzleAssertsTrait.php

示例15: 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;
 }
开发者ID:boxrice007,项目名称:openstack,代码行数:11,代码来源:MetadataTrait.php


注:本文中的GuzzleHttp\Message\ResponseInterface::getHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。