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