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