當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ResponseInterface::hasHeader方法代碼示例

本文整理匯總了PHP中Psr\Http\Message\ResponseInterface::hasHeader方法的典型用法代碼示例。如果您正苦於以下問題:PHP ResponseInterface::hasHeader方法的具體用法?PHP ResponseInterface::hasHeader怎麽用?PHP ResponseInterface::hasHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Psr\Http\Message\ResponseInterface的用法示例。


在下文中一共展示了ResponseInterface::hasHeader方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setHeadersFromArray

 /**
  * Add headers represented by an array of header lines.
  *
  * @param string[] $headers Response headers as array of header lines.
  *
  * @return $this
  *
  * @throws \UnexpectedValueException For invalid header values.
  * @throws \InvalidArgumentException For invalid status code arguments.
  */
 public function setHeadersFromArray(array $headers)
 {
     $statusLine = trim(array_shift($headers));
     $parts = explode(' ', $statusLine, 3);
     if (count($parts) < 2 || substr(strtolower($parts[0]), 0, 5) !== 'http/') {
         throw new \UnexpectedValueException(sprintf('"%s" is not a valid HTTP status line', $statusLine));
     }
     $reasonPhrase = count($parts) > 2 ? $parts[2] : '';
     $this->response = $this->response->withStatus((int) $parts[1], $reasonPhrase)->withProtocolVersion(substr($parts[0], 5));
     foreach ($headers as $headerLine) {
         $headerLine = trim($headerLine);
         if ('' === $headerLine) {
             continue;
         }
         $parts = explode(':', $headerLine, 2);
         if (count($parts) !== 2) {
             throw new \UnexpectedValueException(sprintf('"%s" is not a valid HTTP header line', $headerLine));
         }
         $name = trim(urldecode($parts[0]));
         $value = trim(urldecode($parts[1]));
         if ($this->response->hasHeader($name)) {
             $this->response = $this->response->withAddedHeader($name, $value);
         } else {
             $this->response = $this->response->withHeader($name, $value);
         }
     }
     return $this;
 }
開發者ID:Nyholm,項目名稱:message,代碼行數:38,代碼來源:ResponseBuilder.php

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

示例3: getHeaderLine

 /**
  * {@inheritDoc}
  */
 public function getHeaderLine($name, $default = null)
 {
     if (!$this->decoratedResponse->hasHeader($name)) {
         return $default;
     }
     return $this->decoratedResponse->getHeaderLine($name);
 }
開發者ID:DenLilleMand,項目名稱:christianssite,代碼行數:10,代碼來源:Psr7ResponseDecorator.php

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

示例5: __construct

 /**
  * @param string $message
  * @param ResponseInterface $response
  * @param \DateTime $responseDateTime
  */
 public function __construct($message, ResponseInterface $response, \DateTime $responseDateTime)
 {
     parent::__construct($message, intval($response->getStatusCode()));
     $this->response = $response;
     $this->responseDateTime = $responseDateTime;
     $this->retrySeconds = $response->hasHeader('Retry-After') ? intval($response->getHeaderLine('Retry-After')) : null;
 }
開發者ID:Hikariii,項目名稱:php-box-view,代碼行數:12,代碼來源:NotAvailableException.php

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

示例7: __construct

 /**
  * WosObjectId constructor.
  *
  * @param ResponseInterface $httpResponse
  */
 public function __construct(ResponseInterface $httpResponse)
 {
     if (!$httpResponse->hasHeader('x-ddn-oid')) {
         throw new InvalidResponseException('x-ddn-oid', 'reserve object');
     }
     $this->objectId = $httpResponse->getHeaderLine('x-ddn-oid');
 }
開發者ID:caseyamcl,項目名稱:wosclient,代碼行數:12,代碼來源:WosObjectId.php

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

示例9: createStream

 /**
  * Create the stream.
  *
  * @param $socket
  * @param ResponseInterface $response
  *
  * @return Stream
  */
 protected function createStream($socket, ResponseInterface $response)
 {
     $size = null;
     if ($response->hasHeader('Content-Length')) {
         $size = (int) $response->getHeaderLine('Content-Length');
     }
     return new Stream($socket, $size);
 }
開發者ID:xabbuh,項目名稱:socket-client,代碼行數:16,代碼來源:ResponseReader.php

示例10: __construct

 /**
  * WosObject constructor.
  *
  * @param ResponseInterface $httpResponse
  */
 public function __construct(ResponseInterface $httpResponse)
 {
     if (!$httpResponse->hasHeader('x-ddn-oid')) {
         throw new InvalidResponseException('x-ddn-oid', 'get object');
     }
     $this->responseData = $httpResponse->getBody();
     $this->metadata = new WosObjectMetadata($httpResponse);
     $this->objectId = new WosObjectId($httpResponse);
 }
開發者ID:caseyamcl,項目名稱:wosclient,代碼行數:14,代碼來源:WosObject.php

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

示例12: checkRedirect

 /**
  * @param RequestInterface  $request
  * @param array             $options
  * @param ResponseInterface|PromiseInterface $response
  *
  * @return ResponseInterface|PromiseInterface
  */
 public function checkRedirect(RequestInterface $request, array $options, ResponseInterface $response)
 {
     if (substr($response->getStatusCode(), 0, 1) != '3' || !$response->hasHeader('Location')) {
         return $response;
     }
     $this->guardMax($request, $options);
     $nextRequest = $this->modifyRequest($request, $options, $response);
     return $this($nextRequest, $options);
 }
開發者ID:08euccs014,項目名稱:TrueAnalytics,代碼行數:16,代碼來源:RedirectMiddleware.php

示例13: emit

 /**
  * @param Psr7Response
  * @param ReactResponse
  * @return void
  */
 private function emit(Psr7Response $psr7Response, ReactResponse $reactResponse)
 {
     if (!$psr7Response->hasHeader('Content-Type')) {
         $psr7Response = $psr7Response->withHeader('Content-Type', 'text/html');
     }
     $reactResponse->writeHead($psr7Response->getStatusCode(), $psr7Response->getHeaders());
     $body = $psr7Response->getBody();
     $body->rewind();
     $reactResponse->end($body->getContents());
     $body->close();
 }
開發者ID:phly,項目名稱:react2psr7,代碼行數:16,代碼來源:ReactRequestHandler.php

示例14: getResponseAsJson

 /**
  * Returns the json object if the response contains valid json, otherwise null.
  *
  * @param ResponseInterface $response
  * @return mixed|null
  */
 protected function getResponseAsJson(ResponseInterface $response)
 {
     if ($response->hasHeader('Content-Type')) {
         $typeHeader = $response->getHeader('Content-Type');
         $contentType = array_shift($typeHeader);
         if (stripos($contentType, 'application/json') === 0) {
             return json_decode($response->getBody(), false);
         }
     }
     return null;
 }
開發者ID:gw2treasures,項目名稱:gw2api,代碼行數:17,代碼來源:ApiHandler.php

示例15: injectContentLength

 /**
  * Inject the Content-Length header if is not already present.
  *
  * @param ResponseInterface $response
  * @return ResponseInterface
  */
 private function injectContentLength(ResponseInterface $response)
 {
     if (!$response->hasHeader('Content-Length')) {
         // PSR-7 indicates int OR null for the stream size; for null values,
         // we will not auto-inject the Content-Length.
         if (null !== $response->getBody()->getSize()) {
             return $response->withHeader('Content-Length', (string) $response->getBody()->getSize());
         }
     }
     return $response;
 }
開發者ID:DenLilleMand,項目名稱:christianssite,代碼行數:17,代碼來源:SapiEmitterTrait.php


注:本文中的Psr\Http\Message\ResponseInterface::hasHeader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。