本文整理汇总了PHP中Symfony\Component\HttpFoundation\StreamedResponse::setEtag方法的典型用法代码示例。如果您正苦于以下问题:PHP StreamedResponse::setEtag方法的具体用法?PHP StreamedResponse::setEtag怎么用?PHP StreamedResponse::setEtag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\StreamedResponse
的用法示例。
在下文中一共展示了StreamedResponse::setEtag方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}