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


PHP ResponseInterface::getHeaderLine方法代码示例

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


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

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

示例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")) {
         $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

示例3: deserialize

 /**
  * @param ResponseInterface $response
  * @param string            $class
  *
  * @return array
  */
 public function deserialize(ResponseInterface $response, $class)
 {
     $body = $response->getBody()->__toString();
     if (strpos($response->getHeaderLine('Content-Type'), 'application/json') !== 0) {
         throw new DeserializeException('The ArrayDeserializer cannot deserialize response with Content-Type:' . $response->getHeaderLine('Content-Type'));
     }
     $content = json_decode($body, true);
     if (JSON_ERROR_NONE !== json_last_error()) {
         throw new DeserializeException(sprintf('Error (%d) when trying to json_decode response', json_last_error()));
     }
     return $content;
 }
开发者ID:mailgun,项目名称:mailgun-php,代码行数:18,代码来源:ArrayDeserializer.php

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

示例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")) {
         $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

示例6: modify

 public function modify(ResponseInterface $response) : ResponseInterface
 {
     if (false === strpos($response->getHeaderLine('Content-Type'), 'application/json')) {
         return $response;
     }
     return $response->withHeader('Content-Type', $this->contentType);
 }
开发者ID:ThrusterIO,项目名称:http-modifiers,代码行数:7,代码来源:VendorSpecificJsonHeaderModifier.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: sendBody

 /**
  * Send body as response.
  *
  * @param   ResponseInterface  $response  Response object.
  *
  * @return  void
  */
 public function sendBody(ResponseInterface $response)
 {
     $range = $this->getContentRange($response->getHeaderLine('content-range'));
     $maxBufferLength = $this->getMaxBufferLength() ?: 8192;
     if ($range === false) {
         $body = $response->getBody();
         $body->rewind();
         while (!$body->eof()) {
             echo $body->read($maxBufferLength);
             $this->delay();
         }
         return;
     }
     list($unit, $first, $last, $length) = array_values($range);
     ++$last;
     $body = $response->getBody();
     $body->seek($first);
     $position = $first;
     while (!$body->eof() && $position < $last) {
         // The latest part
         if ($position + $maxBufferLength > $last) {
             echo $body->read($last - $position);
             $this->delay();
             break;
         }
         echo $body->read($maxBufferLength);
         $position = $body->tell();
         $this->delay();
     }
 }
开发者ID:ventoviro,项目名称:windwalker-http,代码行数:37,代码来源:StreamOutput.php

示例9: jsonFromResponse

 /**
  * Decodes a JSON response.
  *
  * @param ResponseInterface $response
  * @param bool              $assoc [optional] Return an associative array?
  * @return mixed
  */
 static function jsonFromResponse(ResponseInterface $response, $assoc = false)
 {
     if ($response->getHeaderLine('Content-Type') != 'application/json') {
         throw new \RuntimeException("HTTP response is not of type JSON");
     }
     return json_decode($response->getBody(), $assoc);
 }
开发者ID:electro-framework,项目名称:framework,代码行数:14,代码来源:Http.php

示例10: extractHeader

 /**
  * Extract a single header from the response into the result.
  */
 private function extractHeader($name, Shape $shape, ResponseInterface $response, &$result)
 {
     $value = $response->getHeaderLine($shape['locationName'] ?: $name);
     switch ($shape->getType()) {
         case 'float':
         case 'double':
             $value = (double) $value;
             break;
         case 'long':
             $value = (int) $value;
             break;
         case 'boolean':
             $value = filter_var($value, FILTER_VALIDATE_BOOLEAN);
             break;
         case 'blob':
             $value = base64_decode($value);
             break;
         case 'timestamp':
             try {
                 $value = new DateTimeResult($value);
                 break;
             } catch (\Exception $e) {
                 // If the value cannot be parsed, then do not add it to the
                 // output structure.
                 return;
             }
     }
     $result[$name] = $value;
 }
开发者ID:abdala,项目名称:generic-api-client,代码行数:32,代码来源:AbstractRestParser.php

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

示例12: __invoke

 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     if (false === strpos($response->getHeaderLine('Content-Type'), 'application/json')) {
         return $next($request, $response);
     }
     return $next($request, $response->withHeader('Content-Type', $this->contentType));
 }
开发者ID:ThrusterIO,项目名称:http-middlewares,代码行数:7,代码来源:VendorSpecificJsonHeaderMiddleware.php

示例13: supportPagination

 /** {@inheritdoc} */
 public function supportPagination(array $data, ResponseInterface $response, ResponseDefinition $responseDefinition)
 {
     $support = true;
     foreach ($this->paginationHeaders as $headerName) {
         $support = $support & $response->getHeaderLine($headerName) !== '';
     }
     return (bool) $support;
 }
开发者ID:eleven-labs,项目名称:api-service,代码行数:9,代码来源:PaginationHeader.php

示例14: extractData

 /**
  * @return array
  */
 public function extractData()
 {
     if (false !== $this->data) {
         return $this->data;
     }
     $stream = $this->response->getBody();
     if ($stream->tell()) {
         $stream->rewind();
     }
     $body = $stream->getContents();
     $contentType = $this->response->getHeaderLine('Content-Type');
     $contentTypeParts = explode(';', $contentType);
     $mimeType = trim(reset($contentTypeParts));
     $data = static::parseStringByFormat($body, $mimeType);
     $this->data = $data;
     return $data;
 }
开发者ID:subscribo,项目名称:psr-http-message-tools,代码行数:20,代码来源:ResponseParser.php

示例15: getExpiration

 /**
  * Check the cache headers and return the expiration time.
  *
  * @param ResponseInterface $response
  *
  * @return Datetime|null
  */
 private static function getExpiration(ResponseInterface $response)
 {
     //Cache-Control
     $cacheControl = $response->getHeaderLine('Cache-Control');
     if (!empty($cacheControl)) {
         $cacheControl = self::parseCacheControl($cacheControl);
         //Max age
         if (isset($cacheControl['max-age'])) {
             return new Datetime('@' . (time() + (int) $cacheControl['max-age']));
         }
     }
     //Expires
     $expires = $response->getHeaderLine('Expires');
     if (!empty($expires)) {
         return new Datetime($expires);
     }
 }
开发者ID:basz,项目名称:psr7-middlewares,代码行数:24,代码来源:Cache.php


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