本文整理汇总了PHP中Illuminate\Http\Response::setLastModified方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setLastModified方法的具体用法?PHP Response::setLastModified怎么用?PHP Response::setLastModified使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Http\Response
的用法示例。
在下文中一共展示了Response::setLastModified方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getResource
public function getResource(Request $request, Log $logger, $path)
{
// Get date metadata and calculate ETag
$timestamp = $this->fs->getTimestamp($path);
$ETag = md5($path . $timestamp);
$date = new DateTime("@{$timestamp}");
$response = new Response();
$response->setLastModified($date)->setEtag($ETag, true)->setPublic();
// Check modified date and Etag before attempting to retrieve actual content
if ($response->isNotModified($request)) {
return $response;
}
$content = $this->fs->read($path);
if (!$content) {
// We had a false positive from the cache!!
$this->deleteFromCache($path);
$logger->warning('File not found (cache false positive)', array('path' => $path));
abort(404);
}
$contentType = $this->fs->getMimetype($path);
if (env('EXAMPLE_DIR') && starts_with($path, env('EXAMPLE_DIR'))) {
// Path is within our "examples" directory, force the file to be downloaded
$disposition = $response->headers->makeDisposition(HeaderBag::DISPOSITION_ATTACHMENT, basename($path));
$response->header('Content-Disposition', $disposition);
}
return $response->header('Content-Type', $contentType)->setContent($content);
}
示例2: render
/**
* TODO: добавить кеширование вывода
*
* @param FrontendPage $frontPage
* @return \Illuminate\View\View|null
* @throws LayoutNotFoundException
*/
protected function render(FrontendPage $frontPage)
{
event('frontend.found', [$frontPage]);
app()->singleton('frontpage', function () use($frontPage) {
return $frontPage;
});
$layout = $frontPage->getLayoutView();
if (is_null($layout)) {
throw new LayoutNotFoundException();
}
$widgetCollection = new PageWidgetCollection($frontPage);
$html = (string) $frontPage->getLayoutView();
if (auth()->check() and auth()->user()->hasRole(['administrator', 'developer'])) {
$injectHTML = (string) view('cms::app.partials.toolbar');
// Insert system HTML before closed tag body
$matches = preg_split('/(<\\/body>)/i', $html, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
if (count($matches) > 1) {
/* assemble the HTML output back with the iframe code in it */
$html = $matches[0] . $injectHTML . $matches[1] . $matches[2];
}
}
$response = new Response();
$response->header('Content-Type', $frontPage->getMime());
if (config('cms.show_response_sign', TRUE)) {
$response->header('X-Powered-CMS', \CMS::NAME . '/' . \CMS::VERSION);
}
$response->setContent($html);
// Set the ETag header
$response->setEtag(sha1($html));
$response->setLastModified($frontPage->getCreatedAt());
// mark the response as either public or private
$response->setPublic();
// Check that the Response is not modified for the given Request
if ($response->isNotModified($this->request)) {
// return the 304 Response immediately
return $response;
}
return $response;
}
示例3: 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;
}