本文整理汇总了PHP中Symfony\Component\HttpFoundation\StreamedResponse::setMaxAge方法的典型用法代码示例。如果您正苦于以下问题:PHP StreamedResponse::setMaxAge方法的具体用法?PHP StreamedResponse::setMaxAge怎么用?PHP StreamedResponse::setMaxAge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\StreamedResponse
的用法示例。
在下文中一共展示了StreamedResponse::setMaxAge方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setLastModified
public function setLastModified($timestamp = 0, $max_age = 0)
{
$time = new \DateTime('@' . $timestamp);
$etag = md5($this->builder->getTheme()->getDir() . $this->builder->getStyle() . '|' . $timestamp . '|' . $max_age);
$this->response->headers->addCacheControlDirective('must-revalidate', true);
$this->response->setLastModified($time);
$this->response->setEtag($etag);
$this->response->setMaxAge($max_age);
}
示例2: setHeaders
/**
* Set the streamed response headers.
* @param StreamedResponse $response The response object.
* @return StreamedResponse
*/
public function setHeaders(StreamedResponse $response)
{
$response->headers->set('Content-Type', $this->cache->getMimetype($this->path));
$response->headers->set('Content-Length', $this->cache->getSize($this->path));
$response->setPublic();
$response->setMaxAge(31536000);
$response->setExpires(date_create()->modify('+1 years'));
$response->setLastModified(date_create()->setTimestamp($this->cache->getTimestamp($this->path)));
$response->isNotModified($this->request);
return $response;
}
示例3: execute
public function execute(Request $request, WorkingFolder $workingFolder, EventDispatcher $dispatcher, Config $config)
{
$fileName = (string) $request->query->get('fileName');
$thumbnailFileName = (string) $request->query->get('thumbnail');
if (!File::isValidName($fileName, $config->get('disallowUnsafeCharacters'))) {
throw new InvalidRequestException(sprintf('Invalid file name: %s', $fileName));
}
$cacheLifetime = (int) $request->query->get('cache');
if (!$workingFolder->containsFile($fileName)) {
throw new FileNotFoundException();
}
if ($thumbnailFileName) {
if (!File::isValidName($thumbnailFileName, $config->get('disallowUnsafeCharacters'))) {
throw new InvalidRequestException(sprintf('Invalid resized image file name: %s', $fileName));
}
if (!$workingFolder->getResourceType()->isAllowedExtension(pathinfo($thumbnailFileName, PATHINFO_EXTENSION))) {
throw new InvalidExtensionException();
}
$resizedImageRespository = $this->app->getResizedImageRepository();
$file = $resizedImageRespository->getExistingResizedImage($workingFolder->getResourceType(), $workingFolder->getClientCurrentFolder(), $fileName, $thumbnailFileName);
$dataStream = $file->readStream();
} else {
$file = new DownloadedFile($fileName, $this->app);
$file->isValid();
$dataStream = $workingFolder->readStream($file->getFilename());
}
$proxyDownload = new ProxyDownloadEvent($this->app, $file);
$dispatcher->dispatch(CKFinderEvent::PROXY_DOWNLOAD, $proxyDownload);
if ($proxyDownload->isPropagationStopped()) {
throw new AccessDeniedException();
}
$response = new StreamedResponse();
$response->headers->set('Content-Type', $file->getMimeType());
$response->headers->set('Content-Length', $file->getSize());
$response->headers->set('Content-Disposition', 'inline; filename="' . $fileName . '"');
if ($cacheLifetime > 0) {
Utils::removeSessionCacheHeaders();
$response->setPublic();
$response->setEtag(dechex($file->getTimestamp()) . "-" . dechex($file->getSize()));
$lastModificationDate = new \DateTime();
$lastModificationDate->setTimestamp($file->getTimestamp());
$response->setLastModified($lastModificationDate);
if ($response->isNotModified($request)) {
return $response;
}
$response->setMaxAge($cacheLifetime);
$expireTime = new \DateTime();
$expireTime->modify('+' . $cacheLifetime . 'seconds');
$response->setExpires($expireTime);
}
$chunkSize = 1024 * 100;
$response->setCallback(function () use($dataStream, $chunkSize) {
if ($dataStream === false) {
return false;
}
while (!feof($dataStream)) {
echo fread($dataStream, $chunkSize);
flush();
@set_time_limit(8);
}
return true;
});
return $response;
}