本文整理汇总了PHP中Illuminate\Http\Response::setExpires方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setExpires方法的具体用法?PHP Response::setExpires怎么用?PHP Response::setExpires使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Http\Response
的用法示例。
在下文中一共展示了Response::setExpires方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cacheResponse
/**
* Cache the response 1 year (31536000 sec)
*/
protected function cacheResponse(Response $response)
{
$response->setSharedMaxAge(31536000);
$response->setMaxAge(31536000);
$response->setExpires(new \DateTime('+1 year'));
return $response;
}
示例2: get
public static function get($file = null)
{
$directory = env('DJEM_DEBUG', false) ? 'panel' : 'panel-compiled';
if (empty($file)) {
$file = 'index.html';
}
$public = realpath(__DIR__ . '/../../../' . $directory);
$file = realpath($public . '/' . preg_replace('|[^-_0-9a-z/.]|i', '', $file));
if (!is_file($file) || substr($file, 0, strlen($public)) !== $public) {
abort(404);
}
// @codeCoverageIgnore
$response = new Response(file_get_contents($file), 200, ['Content-type' => self::getContentType($file)]);
$response->setSharedMaxAge(3600);
$response->setMaxAge(3600);
$response->setExpires(new \DateTime('+1 hour'));
return $response;
}
示例3: setCacheHeaders
/**
* Set cache headers and 304 not modify if needed.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Http\Response $response
*/
protected function setCacheHeaders($request, $response)
{
if (starts_with($request->getPathInfo(), ['/images'])) {
$stat = stat(session()->pull('requestImagePath'));
} else {
if (($view = $response->getOriginalContent()) instanceof View) {
$stat = stat($view->getPath());
}
}
if (isset($stat)) {
$response->setCache(['etag' => md5("{$stat['ino']}|{$stat['mtime']}|{$stat['size']}"), 'public' => true]);
$response->setExpires(Carbon::now()->addDays(30));
if (null !== ($etag = $request->headers->get('If-None-Match')) || null !== $request->headers->get('If-Modified-Since')) {
$etags = explode('-', $etag, -1);
$request->headers->set('If-None-Match', count($etags) ? $etags[0] . '"' : $etag);
$response->isNotModified($request);
}
}
}
示例4: getDisplayAttachment
/**
* Display an attachment file such as image
*
* @param Project $project
* @param Issue $issue
* @param Attachment $attachment
* @param Request $request
*
* @return Response
*/
public function getDisplayAttachment(Project $project, Issue $issue, Attachment $attachment, Request $request)
{
$issue->setRelation('project', $project);
$attachment->setRelation('issue', $issue);
$path = config('tinyissue.uploads_dir') . '/' . $issue->project_id . '/' . $attachment->upload_token . '/' . $attachment->filename;
$storage = \Storage::disk('local');
$length = $storage->size($path);
$time = $storage->lastModified($path);
$type = $storage->getDriver()->getMimetype($path);
$response = new Response();
$response->setEtag(md5($time . $path));
$response->setExpires(new \DateTime('@' . ($time + 60)));
$response->setLastModified(new \DateTime('@' . $time));
$response->setPublic();
$response->setStatusCode(200);
$response->header('Content-Type', $type);
$response->header('Content-Length', $length);
$response->header('Content-Disposition', 'inline; filename="' . $attachment->filename . '"');
$response->header('Cache-Control', 'must-revalidate');
if ($response->isNotModified($request)) {
// Return empty response if not modified
return $response;
}
// Return file if first request / modified
$response->setContent($storage->get($path));
return $response;
}