本文整理匯總了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;
}