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


PHP Response::getDate方法代码示例

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


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

示例1: createRevalidationRequest

 /**
  * Creates a request to use for revalidation
  *
  * @param RequestInterface $request  Request
  * @param Response         $response Response to revalidate
  *
  * @return RequestInterface returns a revalidation request
  */
 protected function createRevalidationRequest(RequestInterface $request, Response $response)
 {
     $revalidate = clone $request;
     $revalidate->removeHeader('Pragma')->removeHeader('Cache-Control')->setHeader('If-Modified-Since', $response->getDate());
     if ($response->getEtag()) {
         $revalidate->setHeader('If-None-Match', '"' . $response->getEtag() . '"');
     }
     // Remove any cache plugins that might be on the request
     $revalidate->getEventDispatcher()->removeSubscriber($this->plugin);
     return $revalidate;
 }
开发者ID:KANU82,项目名称:guzzle,代码行数:19,代码来源:DefaultRevalidation.php

示例2: createRevalidationRequest

 protected function createRevalidationRequest(RequestInterface $request, Response $response)
 {
     $revalidate = clone $request;
     $revalidate->removeHeader('Pragma')->removeHeader('Cache-Control')->setHeader('If-Modified-Since', $response->getLastModified() ?: $response->getDate());
     if ($response->getEtag()) {
         $revalidate->setHeader('If-None-Match', $response->getEtag());
     }
     $dispatcher = $revalidate->getEventDispatcher();
     foreach ($dispatcher->getListeners() as $eventName => $listeners) {
         foreach ($listeners as $listener) {
             if (is_array($listener) && $listener[0] instanceof CachePlugin) {
                 $dispatcher->removeListener($eventName, $listener);
             }
         }
     }
     return $revalidate;
 }
开发者ID:Ryu0621,项目名称:SaNaVi,代码行数:17,代码来源:DefaultRevalidation.php

示例3: cache

 /**
  * {@inheritdoc}
  */
 public function cache($key, Response $response, $ttl = null)
 {
     if ($ttl === null) {
         $ttl = $this->defaultTtl;
     }
     if ($ttl) {
         $response->setHeader('X-Guzzle-Cache', "key={$key}, ttl={$ttl}");
         // Remove excluded headers from the response  (see RFC 2616:13.5.1)
         foreach ($this->excludeResponseHeaders as $header) {
             $response->removeHeader($header);
         }
         // Add a Date header to the response if none is set (for validation)
         if (!$response->getDate()) {
             $response->setHeader('Date', Utils::getHttpDate('now'));
         }
         $this->cache->save($key, array($response->getStatusCode(), $response->getHeaders()->getAll(), $response->getBody(true)), $ttl);
     }
 }
开发者ID:KANU82,项目名称:guzzle,代码行数:21,代码来源:DefaultCacheStorage.php

示例4: createRevalidationRequest

 /**
  * Creates a request to use for revalidation
  *
  * @param RequestInterface $request  Request
  * @param Response         $response Response to revalidate
  *
  * @return RequestInterface returns a revalidation request
  */
 protected function createRevalidationRequest(RequestInterface $request, Response $response)
 {
     $revalidate = clone $request;
     $revalidate->removeHeader('Pragma')->removeHeader('Cache-Control')->setHeader('If-Modified-Since', $response->getLastModified() ?: $response->getDate());
     if ($response->getEtag()) {
         $revalidate->setHeader('If-None-Match', '"' . $response->getEtag() . '"');
     }
     // Remove any cache plugins that might be on the request to prevent infinite recursive revalidations
     $dispatcher = $revalidate->getEventDispatcher();
     foreach ($dispatcher->getListeners() as $eventName => $listeners) {
         foreach ($listeners as $listener) {
             if ($listener[0] instanceof CachePlugin) {
                 $dispatcher->removeListener($eventName, $listener);
             }
         }
     }
     return $revalidate;
 }
开发者ID:diandianxiyu,项目名称:Yii2Api,代码行数:26,代码来源:DefaultRevalidation.php

示例5: cache

 public function cache($key, Response $response, $ttl = null)
 {
     if ($ttl === null) {
         $ttl = $this->defaultTtl;
     }
     $ttl += $response->getMaxAge();
     if ($ttl) {
         $response->setHeader('X-Guzzle-Cache', "key={$key}; ttl={$ttl}");
         // Remove excluded headers from the response  (see RFC 2616:13.5.1)
         foreach ($this->excludeResponseHeaders as $header) {
             $response->removeHeader($header);
         }
         // Add a Date header to the response if none is set (for validation)
         if (!$response->getDate()) {
             $response->setHeader('Date', gmdate(ClientInterface::HTTP_DATE));
         }
         $this->cache->save($key, array($response->getStatusCode(), $response->getHeaders()->toArray(), $response->getBody(true)), $ttl);
     }
 }
开发者ID:creazy412,项目名称:vmware-win10-c65-drupal7,代码行数:19,代码来源:DefaultCacheStorage.php

示例6: onRequestBeforeSend

 /**
  * Check if a response in cache will satisfy the request before sending
  *
  * @param Event $event
  */
 public function onRequestBeforeSend(Event $event)
 {
     $request = $event['request'];
     if (!$this->canCache->canCacheRequest($request)) {
         return;
     }
     $hashKey = $this->keyProvider->getCacheKey($request);
     $this->cached[$request] = $hashKey;
     // If the cached data was found, then make the request into a
     // manually set request
     if ($cachedData = $this->storage->fetch($hashKey)) {
         unset($this->cached[$request]);
         $response = new Response($cachedData[0], $cachedData[1], $cachedData[2]);
         $response->setHeader('Age', time() - strtotime($response->getDate() ?: 'now'));
         if (!$response->hasHeader('X-Guzzle-Cache')) {
             $response->setHeader('X-Guzzle-Cache', "key={$hashKey}");
         }
         // Validate that the response satisfies the request
         if ($this->canResponseSatisfyRequest($request, $response)) {
             $request->setResponse($response);
         }
     }
 }
开发者ID:KANU82,项目名称:guzzle,代码行数:28,代码来源:CachePlugin.php

示例7: saveCache

 /**
  * Save data to the cache adapter
  *
  * @param string   $key      The cache key
  * @param Response $response The response to cache
  * @param int      $lifetime Amount of seconds to cache
  *
  * @return int Returns the lifetime of the cached data
  */
 protected function saveCache($key, Response $response, $lifetime = null)
 {
     $lifetime = $lifetime ?: $this->defaultLifetime;
     // If the data is cacheable, then save it to the cache adapter
     if ($lifetime) {
         // Remove excluded headers from the response  (see RFC 2616:13.5.1)
         foreach ($this->excludeResponseHeaders as $header) {
             $response->removeHeader($header);
         }
         // Add a Date header to the response if none is set (for validation)
         if (!$response->getDate()) {
             $response->setHeader('Date', Utils::getHttpDate('now'));
         }
         $data = array('c' => $response->getStatusCode(), 'h' => $response->getHeaders(), 'b' => $response->getBody(true));
         if ($this->serialize) {
             $data = serialize($data);
         }
         $this->getCacheAdapter()->save($key, $data, $lifetime);
     }
     return $lifetime;
 }
开发者ID:norv,项目名称:guzzle,代码行数:30,代码来源:CachePlugin.php

示例8: onRequestException

 /**
  * If possible, set a cache response on a cURL exception
  *
  * @param Event $event
  *
  * @return null
  */
 public function onRequestException(Event $event)
 {
     if (!$event['exception'] instanceof CurlException) {
         return;
     }
     $request = $event['request'];
     if (!$this->canCache->canCacheRequest($request)) {
         return;
     }
     $cacheKey = $this->keyProvider->getCacheKey($request);
     if ($cachedData = $this->storage->fetch($cacheKey)) {
         $response = new Response($cachedData[0], $cachedData[1], $cachedData[2]);
         $response->setHeader('Age', time() - strtotime($response->getDate() ?: 'now'));
         if (!$this->canResponseSatisfyFailedRequest($request, $response)) {
             return;
         }
         $request->getParams()->set('cache.hit', 'error');
         $request->setResponse($response);
         $event->stopPropagation();
     }
 }
开发者ID:creazy412,项目名称:vmware-win10-c65-drupal7,代码行数:28,代码来源:CachePlugin.php


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