本文整理汇总了PHP中Symfony\Component\HttpFoundation\StreamedResponse::setETag方法的典型用法代码示例。如果您正苦于以下问题:PHP StreamedResponse::setETag方法的具体用法?PHP StreamedResponse::setETag怎么用?PHP StreamedResponse::setETag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\StreamedResponse
的用法示例。
在下文中一共展示了StreamedResponse::setETag方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: manifestAction
/**
* @param string $build
* @param Request $request
* @return Response
*/
public function manifestAction($build, Request $request)
{
$this->closeSession($request);
try {
$manifest = $this->application->getManifest($build);
} catch (FileNotFoundException $e) {
throw new NotFoundHttpException('Not Found', $e);
}
$response = new StreamedResponse(function () {
echo '';
});
$response->setETag($manifest->computeETag())->setLastModified(\DateTime::createFromFormat('U', $manifest->getMTime()))->setPublic();
if ($response->isNotModified($request)) {
return $response;
}
$response->setCallback(function () use($manifest) {
echo $manifest->getContent();
});
$response->headers->set('Content-Type', 'application/json');
return $response;
}
示例2: staticFile
/**
* The controller for serving static files.
*
* @param Request $request
* the current request
* @param Application $app
* the Silex application
*
* @return Response
* redirects to the instance details page or 404 on invalid input
*/
public function staticFile(Request $request, Application $app)
{
$fileParam = str_replace('..', '', $request->get('file'));
$file = __DIR__ . '/../static/' . $fileParam;
if (!$fileParam || !file_exists($file)) {
return $this->getNotFoundPage($app, $app['translator']->trans('crudlex.resourceNotFound'));
}
$mimeTypes = new MimeTypes();
$mimeType = $mimeTypes->getMimeType($file);
$size = filesize($file);
$streamedFileResponse = new StreamedFileResponse();
$response = new StreamedResponse($streamedFileResponse->getStreamedFileFunction($file), 200, ['Content-Type' => $mimeType, 'Content-Disposition' => 'attachment; filename="' . basename($file) . '"', 'Content-length' => $size]);
$response->setETag(filemtime($file))->setPublic()->isNotModified($request);
$response->send();
return $response;
}