当前位置: 首页>>代码示例>>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;未经允许,请勿转载。