本文整理汇总了PHP中Guzzle\Http\Message\Response::getLastModified方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::getLastModified方法的具体用法?PHP Response::getLastModified怎么用?PHP Response::getLastModified使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Message\Response
的用法示例。
在下文中一共展示了Response::getLastModified方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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->getLastModified() ?: $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;
}
示例2: 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');
if ($response->getLastModified()) {
$revalidate->setHeader('If-Modified-Since', $response->getLastModified());
}
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 (is_array($listener) && $listener[0] instanceof CachePlugin) {
$dispatcher->removeListener($eventName, $listener);
}
}
}
return $revalidate;
}
示例3: onRequestError
/**
* If possible, return a cache response on an error
*
* @param Event $event
*/
public function onRequestError(Event $event)
{
$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->setRequest($request);
$response->setHeader('Age', time() - strtotime($response->getLastModified() ?: $response->getDate() ?: 'now'));
if ($this->canResponseSatisfyFailedRequest($request, $response)) {
$request->getParams()->set('cache.hit', 'error');
$this->addResponseHeaders($cacheKey, $request, $response);
$event['response'] = $response;
$event->stopPropagation();
}
}
}