當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。