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


PHP ResponseInterface::hasHeader方法代码示例

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


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

示例1: 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

示例2: getExpected

 private function getExpected(ResponseInterface $response)
 {
     if (!($body = $response->getBody())) {
         return false;
     } elseif ($response->hasHeader('Transfer-Encoding') || $response->hasHeader('Content-Encoding')) {
         // Currently does not support un-gzipping or inflating responses
         return false;
     }
     return call_user_func($this->expectedFn, $response);
 }
开发者ID:bobozhangshao,项目名称:HeartCare,代码行数:10,代码来源:StreamResponse.php

示例3: canValidate

 private function canValidate(ResponseInterface $response)
 {
     if (!($body = $response->getBody())) {
         return false;
     } elseif ($response->hasHeader('Transfer-Encoding') || $response->hasHeader('Content-Encoding')) {
         // Currently does not support un-gzipping or inflating responses
         return false;
     } elseif (!$body->isSeekable()) {
         return false;
     } elseif ($this->sizeCutoff !== null && $body->getSize() > $this->sizeCutoff) {
         return false;
     }
     return true;
 }
开发者ID:bobozhangshao,项目名称:HeartCare,代码行数:14,代码来源:CompleteResponse.php

示例4: 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

示例5: 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

示例6: handle304Response

 private function handle304Response(RequestInterface $request, ResponseInterface $response, ResponseInterface $validated, CompleteEvent $event)
 {
     // Make sure that this response has the same ETag
     if ($validated->getHeader('ETag') !== $response->getHeader('ETag')) {
         // Revalidation failed, so remove from cache and retry.
         $this->storage->delete($request);
         $event->intercept($event->getClient()->send($request));
         return;
     }
     // Replace cached headers with any of these headers from the
     // origin server that might be more up to date
     $modified = false;
     foreach (self::$replaceHeaders as $name) {
         if ($validated->hasHeader($name) && $validated->getHeader($name) != $response->getHeader($name)) {
             $modified = true;
             $response->setHeader($name, $validated->getHeader($name));
         }
     }
     // Store the updated response in cache
     if ($modified) {
         $this->storage->cache($request, $response);
     }
 }
开发者ID:thomaschaaf,项目名称:cache-subscriber,代码行数:23,代码来源:ValidationSubscriber.php

示例7: parseTokenResponse

 /**
  * Parses the fetched tokens.
  *
  * @param $resp GuzzleHttp\Message\ReponseInterface the response.
  * @return array the tokens parsed from the response body.
  */
 public function parseTokenResponse(ResponseInterface $resp)
 {
     $body = $resp->getBody()->getContents();
     if ($resp->hasHeader('Content-Type') && $resp->getHeader('Content-Type') == 'application/x-www-form-urlencoded') {
         $res = array();
         parse_str($body, $res);
         return $res;
     } else {
         // Assume it's JSON; if it's not there needs to be an exception, so
         // we use the json decode exception instead of adding a new one.
         return $resp->json();
     }
 }
开发者ID:dwsupplee,项目名称:google-auth-library-php,代码行数:19,代码来源:OAuth2.php

示例8: theResponseHeaderLocationShouldContainsPath

 /**
  * Checks that the response has header location contains path
  *
  * @Then /^the response header location should contains "([^"]+)"$/
  */
 public function theResponseHeaderLocationShouldContainsPath($path)
 {
     Assertions::assertTrue($this->response->hasHeader('location'));
     Assertions::assertContains($path, $this->response->getHeader('location'));
 }
开发者ID:GoldenLine,项目名称:WebApiExtension,代码行数:10,代码来源:WebApiContext.php

示例9: theOcChecksumHeaderShouldNotBeThere

 /**
  * @Then The OC-Checksum header should not be there
  */
 public function theOcChecksumHeaderShouldNotBeThere()
 {
     if ($this->response->hasHeader('OC-Checksum')) {
         throw new \Exception("Expected no checksum header but got " . $this->response->getHeader('OC-Checksum'));
     }
 }
开发者ID:rchicoli,项目名称:owncloud-core,代码行数:9,代码来源:ChecksumsContext.php


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