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


PHP ResponseInterface::getHeader方法代码示例

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


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

示例1: __construct

 /**
  * @param ResponseInterface $response
  * @param \DateTime $staleAt
  * @param \DateTime|null $staleIfErrorTo if null, detected with the headers (RFC 5861)
  * @param \DateTime $staleWhileRevalidateTo
  */
 public function __construct(ResponseInterface $response, \DateTime $staleAt, \DateTime $staleIfErrorTo = null, \DateTime $staleWhileRevalidateTo = null)
 {
     $this->response = $response;
     $this->staleAt = $staleAt;
     if ($staleIfErrorTo === null) {
         $headersCacheControl = $response->getHeader("Cache-Control");
         if (!in_array("must-revalidate", $headersCacheControl)) {
             foreach ($headersCacheControl as $directive) {
                 $matches = [];
                 if (preg_match('/^stale-if-error=([0-9]*)$/', $directive, $matches)) {
                     $this->staleIfErrorTo = new \DateTime('+' . $matches[1] . 'seconds');
                     break;
                 }
             }
         }
     } else {
         $this->staleIfErrorTo = $staleIfErrorTo;
     }
     if ($staleWhileRevalidateTo === null) {
         foreach ($response->getHeader("Cache-Control") as $directive) {
             $matches = [];
             if (preg_match('/^stale-while-revalidate=([0-9]*)$/', $directive, $matches)) {
                 $this->staleWhileRevalidateTo = new \DateTime('+' . $matches[1] . 'seconds');
                 break;
             }
         }
     } else {
         $this->staleWhileRevalidateTo = $staleWhileRevalidateTo;
     }
 }
开发者ID:royopa,项目名称:guzzle-cache-middleware,代码行数:36,代码来源:CacheEntry.php

示例2: theResponseHeadersShouldContain

 /**
  * @When the response headers should contain :expectedHeader
  */
 public function theResponseHeadersShouldContain($expectedHeader)
 {
     list($headerTitle, $expectedHeaderValue) = explode(':', $expectedHeader);
     $expectedHeaderValue = trim($expectedHeaderValue);
     $headerValuesReceived = $this->responseReceived->getHeader($headerTitle);
     \PHPUnit_Framework_Assert::assertEquals($expectedHeaderValue, $headerValuesReceived[0]);
 }
开发者ID:postalservice14,项目名称:sainsburys-http-service,代码行数:10,代码来源:WebserverContext.php

示例3: getCacheObject

 /**
  * @param RequestInterface $request
  * @param ResponseInterface $response
  * @return CacheEntry|null entry to save, null if can't cache it
  */
 protected function getCacheObject(RequestInterface $request, ResponseInterface $response)
 {
     if (!isset($this->statusAccepted[$response->getStatusCode()])) {
         // Don't cache it
         return;
     }
     $cacheControl = new KeyValueHttpHeader($response->getHeader('Cache-Control'));
     $varyHeader = new KeyValueHttpHeader($response->getHeader('Vary'));
     if ($varyHeader->has('*')) {
         // This will never match with a request
         return;
     }
     if ($cacheControl->has('no-store')) {
         // No store allowed (maybe some sensitives data...)
         return;
     }
     if ($cacheControl->has('no-cache')) {
         // Stale response see RFC7234 section 5.2.1.4
         $entry = new CacheEntry($request, $response, new \DateTime('-1 seconds'));
         return $entry->hasValidationInformation() ? $entry : null;
     }
     foreach ($this->ageKey as $key) {
         if ($cacheControl->has($key)) {
             return new CacheEntry($request, $response, new \DateTime('+' . (int) $cacheControl->get($key) . 'seconds'));
         }
     }
     if ($response->hasHeader('Expires')) {
         $expireAt = \DateTime::createFromFormat(\DateTime::RFC1123, $response->getHeaderLine('Expires'));
         if ($expireAt !== false) {
             return new CacheEntry($request, $response, $expireAt);
         }
     }
     return new CacheEntry($request, $response, new \DateTime('-1 seconds'));
 }
开发者ID:kevinrob,项目名称:guzzle-cache-middleware,代码行数:39,代码来源:PrivateCacheStrategy.php

示例4: _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,代码来源:Guzzle6Connection.php

示例5: getCacheObject

 /**
  * @param ResponseInterface $response
  * @return CacheEntry|null entry to save, null if can't cache it
  */
 protected function getCacheObject(ResponseInterface $response)
 {
     if ($response->hasHeader("Cache-Control")) {
         $cacheControlDirectives = $response->getHeader("Cache-Control");
         if (in_array("no-store", $cacheControlDirectives)) {
             // No store allowed (maybe some sensitives data...)
             return null;
         }
         if (in_array("no-cache", $cacheControlDirectives)) {
             // Stale response see RFC7234 section 5.2.1.4
             $entry = new CacheEntry($response, new \DateTime('-1 seconds'));
             return $entry->hasValidationInformation() ? $entry : null;
         }
         $matches = [];
         if (preg_match('/^max-age=([0-9]*)$/', $response->getHeaderLine("Cache-Control"), $matches)) {
             // Handle max-age header
             return new CacheEntry($response, new \DateTime('+' . $matches[1] . 'seconds'));
         }
     }
     if ($response->hasHeader("Expires")) {
         $expireAt = \DateTime::createFromFormat('D, d M Y H:i:s T', $response->getHeaderLine("Expires"));
         if ($expireAt !== FALSE) {
             return new CacheEntry($response, $expireAt);
         }
     }
     return new CacheEntry($response, new \DateTime('1 days ago'));
 }
开发者ID:royopa,项目名称:guzzle-cache-middleware,代码行数:31,代码来源:PrivateCache.php

示例6: checkResponse

 protected function checkResponse(ResponseInterface $response, $data)
 {
     // Metadata info
     $contentTypeRaw = $response->getHeader('Content-Type');
     $contentTypeArray = explode(';', reset($contentTypeRaw));
     $contentType = reset($contentTypeArray);
     // Response info
     $responseCode = $response->getStatusCode();
     $responseMessage = $response->getReasonPhrase();
     // Data info
     $error = !empty($data['error']) ? $data['error'] : null;
     $errorCode = !empty($error['error_code']) ? $error['error_code'] : $responseCode;
     $errorDescription = !empty($data['error_description']) ? $data['error_description'] : null;
     $errorMessage = !empty($error['error_msg']) ? $error['error_msg'] : $errorDescription;
     $message = $errorMessage ?: $responseMessage;
     // Request/meta validation
     if (399 < $responseCode) {
         throw new IdentityProviderException($message, $responseCode, $data);
     }
     // Content validation
     if ('application/json' != $contentType) {
         throw new IdentityProviderException($message, $responseCode, $data);
     }
     if ($error) {
         throw new IdentityProviderException($errorMessage, $errorCode, $data);
     }
 }
开发者ID:j4k,项目名称:oauth2-vkontakte,代码行数:27,代码来源:Vkontakte.php

示例7: decode

 public static function decode(ResponseInterface $response)
 {
     if ($response->hasHeader('Content-Type') && $response->getHeader('Content-Type')[0] == 'application/json') {
         return json_decode((string) $response->getBody(), true);
     }
     return (string) $response->getBody();
 }
开发者ID:keboola,项目名称:orchestrator-bundle,代码行数:7,代码来源:ResponseDecoder.php

示例8: getCacheObject

 /**
  * @param ResponseInterface $response
  * @return CacheEntry|null entry to save, null if can't cache it
  */
 protected function getCacheObject(ResponseInterface $response)
 {
     if ($response->hasHeader("Cache-Control")) {
         $values = new KeyValueHttpHeader($response->getHeader("Cache-Control"));
         if ($values->has('no-store')) {
             // No store allowed (maybe some sensitives data...)
             return null;
         }
         if ($values->has('no-cache')) {
             // Stale response see RFC7234 section 5.2.1.4
             $entry = new CacheEntry($response, new \DateTime('-1 seconds'));
             return $entry->hasValidationInformation() ? $entry : null;
         }
         if ($values->has('max-age')) {
             return new CacheEntry($response, new \DateTime('+' . $values->get('max-age') . 'seconds'));
         }
         return new CacheEntry($response, new \DateTime());
     }
     if ($response->hasHeader("Expires")) {
         $expireAt = \DateTime::createFromFormat('D, d M Y H:i:s T', $response->getHeaderLine("Expires"));
         if ($expireAt !== FALSE) {
             return new CacheEntry($response, $expireAt);
         }
     }
     return new CacheEntry($response, new \DateTime('-1 seconds'));
 }
开发者ID:h4cc,项目名称:guzzle-cache-middleware,代码行数:30,代码来源:PrivateCache.php

示例9: handleInvalidContentType

 private function handleInvalidContentType(HalClientInterface $client, RequestInterface $request, ResponseInterface $response, $ignoreInvalidContentType)
 {
     if ($ignoreInvalidContentType) {
         return new HalResource($client);
     }
     $types = $response->getHeader('Content-Type') ?: ['none'];
     throw new Exception\BadResponseException(sprintf('Request did not return a valid content type. Returned content type: %s.', implode(', ', $types)), $request, $response, new HalResource($client));
 }
开发者ID:jsor,项目名称:hal-client,代码行数:8,代码来源:HalResourceFactory.php

示例10: Resource

 function it_returns_a_processed_resource(ResponseInterface $response, HttpClient $httpClient, Processor $processor)
 {
     $response->getHeader('content-type')->willReturn(['application/hal+json']);
     $resource = new Resource([], []);
     $httpClient->get('http://api.test.com/')->willReturn($response);
     $processor->process($response, $this)->willReturn($resource);
     $this->get('http://api.test.com/')->shouldReturn($resource);
 }
开发者ID:tomphp,项目名称:hal-client,代码行数:8,代码来源:ClientSpec.php

示例11: getCacheObject

 /**
  * {@inheritdoc}
  */
 protected function getCacheObject(RequestInterface $request, ResponseInterface $response)
 {
     $cacheControl = new KeyValueHttpHeader($response->getHeader('Cache-Control'));
     if ($cacheControl->has('private')) {
         return;
     }
     return parent::getCacheObject($request, $response);
 }
开发者ID:thedeedawg,项目名称:guzzle-cache-middleware,代码行数:11,代码来源:PublicCacheStrategy.php

示例12: getPagination

 /** {@inheritdoc} */
 public function getPagination(array $data, ResponseInterface $response, ResponseDefinition $responseDefinition)
 {
     $paginationLinks = null;
     if ($response->hasHeader('Link')) {
         $links = self::parseHeaderLinks($response->getHeader('Link'));
         $paginationLinks = new PaginationLinks($links['first'], $links['last'], $links['next'], $links['prev']);
     }
     return new Pagination((int) $response->getHeaderLine($this->paginationHeaders['page']), (int) $response->getHeaderLine($this->paginationHeaders['perPage']), (int) $response->getHeaderLine($this->paginationHeaders['totalItems']), (int) $response->getHeaderLine($this->paginationHeaders['totalPages']), $paginationLinks);
 }
开发者ID:eleven-labs,项目名称:api-service,代码行数:10,代码来源:PaginationHeader.php

示例13: __construct

 /**
  * Constructor
  *
  * @param \Psr\Http\Message\ResponseInterface $response
  * @param string $userAgent
  * @throws XRobotsTagParser\Exceptions\XRobotsTagParserException
  */
 public function __construct(ResponseInterface $response, $userAgent = '')
 {
     parent::__construct($userAgent);
     $headers = [];
     foreach ($response->getHeader(parent::HEADER_RULE_IDENTIFIER) as $name => $values) {
         $headers[] = $name . ': ' . implode(' ', $values) . "\r\n";
     }
     $this->parse($headers);
 }
开发者ID:VIPnytt,项目名称:RobotsTagParser,代码行数:16,代码来源:GuzzleHttp.php

示例14: getOrchestrateRequestId

 public function getOrchestrateRequestId()
 {
     $this->settlePromise();
     if ($this->_response) {
         $value = $this->_response->getHeader('X-ORCHESTRATE-REQ-ID');
         return isset($value[0]) ? $value[0] : '';
     }
     return '';
 }
开发者ID:andrefelipe,项目名称:orchestrate-php,代码行数:9,代码来源:AbstractConnection.php

示例15: create

 /**
  *
  * @param RequestInterface $request
  * @param ResponseInterface $response
  * @param \Exception $previous
  * @param array $ctx
  * @return BearerErrorResponseException
  */
 public static function create(RequestInterface $request, ResponseInterface $response = null, \Exception $previous = null, array $ctx = [])
 {
     unset($previous, $ctx);
     $label = 'Bearer error response';
     $bearerReason = self::headerToReason($response->getHeader('WWW-Authenticate'));
     $message = $label . PHP_EOL . implode(PHP_EOL, ['[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[bearer reason] ' . $bearerReason, '[url] ' . $request->getUri()]);
     $exception = new static($message, $request, $response);
     $exception->setBearerReason($bearerReason);
     return $exception;
 }
开发者ID:easybiblabs,项目名称:oauth2-client-php,代码行数:18,代码来源:BearerErrorResponseException.php


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