本文整理匯總了PHP中Symfony\Component\HttpFoundation\StreamedResponse::setPrivate方法的典型用法代碼示例。如果您正苦於以下問題:PHP StreamedResponse::setPrivate方法的具體用法?PHP StreamedResponse::setPrivate怎麽用?PHP StreamedResponse::setPrivate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\HttpFoundation\StreamedResponse
的用法示例。
在下文中一共展示了StreamedResponse::setPrivate方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: showAction
/**
* @Route("/orangegate/media/show/{id}/{format}", name="orangegate_media_show")
*
* @throws NotFoundHttpException
*
* @param string $id
* @param string $format
*
* @return Response
*/
public function showAction($id, $format = 'reference')
{
$media = $this->getMedia($id);
if (!$media) {
throw new NotFoundHttpException(sprintf('unable to find the media with the id : %s', $id));
}
$provider = $this->get($media->getProviderName());
if ($format == 'reference') {
$file = $provider->getReferenceFile($media);
} else {
$file = $provider->getFilesystem()->get($provider->generatePrivateUrl($media, $format));
}
$filePath = sprintf('%s/%s', $provider->getFilesystem()->getAdapter()->getDirectory(), $file->getKey());
if (!$file || !file_exists($filePath)) {
throw new NotFoundHttpException(sprintf('file not exists : %s', $file->getKey()));
}
$response = new StreamedResponse(function () use($file) {
echo $file->getContent();
}, Response::HTTP_OK, array('Content-Type' => $media->getContentType(), 'Content-Disposition' => sprintf('inline; filename="%s"', $media->getMetadataValue('filename'))));
$response->setPrivate();
$response->headers->addCacheControlDirective('max-age', 0);
$response->headers->addCacheControlDirective('no-cache', true);
$response->headers->addCacheControlDirective('no-store', true);
$response->headers->addCacheControlDirective('must-revalidate', true);
return $response;
}