本文整理汇总了PHP中Symfony\Component\HttpFoundation\StreamedResponse::setCallBack方法的典型用法代码示例。如果您正苦于以下问题:PHP StreamedResponse::setCallBack方法的具体用法?PHP StreamedResponse::setCallBack怎么用?PHP StreamedResponse::setCallBack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\StreamedResponse
的用法示例。
在下文中一共展示了StreamedResponse::setCallBack方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fileAction
/**
* @Route(
* "/image/{node}",
* name="claro_image"
* )
*/
public function fileAction(ResourceNode $node)
{
$image = $this->get('claroline.manager.resource_manager')->getResourceFromNode($node);
$response = new StreamedResponse();
$path = $this->container->getParameter('claroline.param.files_directory') . DIRECTORY_SEPARATOR . $image->getHashName();
$response->setCallBack(function () use($path) {
readfile($path);
});
$response->headers->set('Content-Type', $node->getMimeType());
return $response->send();
}
示例2: download
/**
* @EXT\Route(
* "/download/{pdf}",
* name="claro_pdf_download",
* options={"expose"=true}
* )
* @EXT\ParamConverter(
* "pdf",
* class="ClarolinePdfGeneratorBundle:Pdf",
* options={"mapping": {"pdf": "guid"}}
* )
*
* @param array $nodes
* @param bool $forceArchive
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function download(Pdf $pdf)
{
$response = new StreamedResponse();
$file = $this->pdfManager->getFile($pdf);
$response->setCallBack(function () use($file) {
readfile($file);
});
$response->headers->set('Content-Transfer-Encoding', 'octet-stream');
$response->headers->set('Content-Type', 'application/force-download');
$response->headers->set('Content-Disposition', 'attachment; filename=' . urlencode($pdf->getName() . '.pdf'));
$response->headers->set('Content-Type', 'application/pdf');
$response->headers->set('Connection', 'close');
$response->send();
}
示例3: streamMediaAction
/**
* @EXT\Route(
* "resource/media/{node}",
* name="claro_file_get_media",
* options={"expose"=true}
* )
*
* @param integer $id
*
* @return Response
*/
public function streamMediaAction(ResourceNode $node)
{
$collection = new ResourceCollection(array($node));
$this->checkAccess('OPEN', $collection);
$file = $this->get('claroline.manager.resource_manager')->getResourceFromNode($node);
$path = $this->container->getParameter('claroline.param.files_directory') . DIRECTORY_SEPARATOR . $file->getHashName();
$response = new StreamedResponse();
$response->setCallBack(function () use($path) {
readfile($path);
});
$response->headers->set('Content-Type', $node->getMimeType());
$response->send();
return new Response();
}
示例4: downloadAction
/**
* @EXT\Route(
* "/download/invoice/{invoice}",
* name="invoice_download"
* )
*
* @return Response
*/
public function downloadAction(Invoice $invoice)
{
$user = $this->tokenStorage->getToken()->getUser();
if ($invoice->getChart()->getOwner() !== $user && !$this->authorization->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException();
}
$file = $this->invoiceManager->getPdf($invoice);
$response = new StreamedResponse();
$response->setCallBack(function () use($file) {
readfile($file);
});
$response->headers->set('Content-Transfer-Encoding', 'octet-stream');
$response->headers->set('Content-Type', 'application/force-download');
$response->headers->set('Content-Disposition', 'attachment; filename=invoice-' . $invoice->getInvoiceNumber() . '.pdf');
$response->headers->set('Content-Type', 'application/pdf');
$response->headers->set('Connection', 'close');
$response->send();
return new Response();
}
示例5: createResponse
public function createResponse(ViewHandler $handler, View $view, Request $request, $format)
{
$data = $view->getData();
$context = $view->getSerializationContext();
$container = $handler->getContainer();
$format = $view->getFormat();
$file = $container->get('claroline.library.view.serializer.serializer')->serialize($data, $format);
$response = new StreamedResponse();
$response->setCallBack(function () use($file) {
readfile($file);
});
$response->headers->set('Content-Transfer-Encoding', 'octet-stream');
$response->headers->set('Content-Type', 'application/force-download');
$response->headers->set('Content-Disposition', 'attachment; filename=file.' . $format);
switch ($format) {
case 'csv':
$response->headers->set('Content-Type', 'text/csv');
break;
case 'xls':
$response->headers->set('Content-Type', 'application/vnd.ms-excel');
break;
}
return $response;
}
示例6: export
/**
* @EXT\Route("/export/users/{format}", name="claro_admin_export_users")
*
* @return Response
*/
public function export($format)
{
$exporter = $this->container->get('claroline.exporter.' . $format);
$exporterManager = $this->container->get('claroline.manager.exporter_manager');
$file = $exporterManager->export('Claroline\\CoreBundle\\Entity\\User', $exporter);
$response = new StreamedResponse();
$response->setCallBack(function () use($file) {
readfile($file);
});
$response->headers->set('Content-Transfer-Encoding', 'octet-stream');
$response->headers->set('Content-Type', 'application/force-download');
$response->headers->set('Content-Disposition', 'attachment; filename=users.' . $format);
switch ($format) {
case 'csv':
$response->headers->set('Content-Type', 'text/csv');
break;
case 'xls':
$response->headers->set('Content-Type', 'application/vnd.ms-excel');
break;
}
$response->headers->set('Connection', 'close');
return $response;
}
示例7: exportAction
/**
* @EXT\Route(
* "/{workspace}/export",
* name="claro_workspace_export",
* options={"expose"=true}
* )
*/
public function exportAction(Workspace $workspace)
{
$archive = $this->container->get('claroline.manager.transfert_manager')->export($workspace);
$fileName = $workspace->getCode() . '.zip';
$mimeType = 'application/zip';
$response = new StreamedResponse();
$response->setCallBack(function () use($archive) {
readfile($archive);
});
$response->headers->set('Content-Transfer-Encoding', 'octet-stream');
$response->headers->set('Content-Type', 'application/force-download');
$response->headers->set('Content-Disposition', 'attachment; filename=' . urlencode($fileName));
$response->headers->set('Content-Length', filesize($archive));
$response->headers->set('Content-Type', $mimeType);
$response->headers->set('Connection', 'close');
return $response->send();
}
示例8: coursesExportAction
/**
* @EXT\Route(
* "/courses/export",
* name="claro_cursus_courses_export",
* options={"expose"=true}
* )
* @EXT\ParamConverter("authenticatedUser", options={"authenticatedUser" = true})
*/
public function coursesExportAction()
{
$courses = $this->cursusManager->getAllCourses('', 'id', 'ASC', false);
$zipName = 'courses.zip';
$mimeType = 'application/zip';
$file = $this->cursusManager->zipDatas($courses, 'course');
$response = new StreamedResponse();
$response->setCallBack(function () use($file) {
readfile($file);
});
$response->headers->set('Content-Transfer-Encoding', 'octet-stream');
$response->headers->set('Content-Type', 'application/force-download');
$response->headers->set('Content-Disposition', 'attachment; filename=' . urlencode($zipName));
$response->headers->set('Content-Type', $mimeType);
$response->headers->set('Connection', 'close');
$response->send();
return new Response();
}
示例9: onOpen
/**
* @DI\Observe("open_directory")
*
* @param OpenResourceEvent $event
*/
public function onOpen(OpenResourceEvent $event)
{
$dir = $event->getResourceNode();
$file = $this->resourceManager->download(array($dir));
$response = new StreamedResponse();
$response->setCallBack(function () use($file) {
readfile($file);
});
$response->headers->set('Content-Transfer-Encoding', 'octet-stream');
$response->headers->set('Content-Type', 'application/force-download');
$response->headers->set('Content-Disposition', 'attachment; filename=archive');
$response->headers->set('Content-Type', 'application/zip');
$response->headers->set('Connection', 'close');
$event->setResponse($response);
$event->stopPropagation();
}
示例10: exportAction
/**
* @EXT\Route(
* "/export",
* name="claro_resource_export",
* options={"expose"=true}
* )
* @EXT\ParamConverter(
* "nodes",
* class="ClarolineCoreBundle:Resource\ResourceNode",
* options={"multipleIds" = true}
* )
*
* This function takes an array of parameters. Theses parameters are the ids
* of the resources which are going to be exported
* (query string: "ids[]=1&ids[]=2" ...).
*
* @param array $nodes
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function exportAction(array $nodes)
{
if (count($nodes) === 0) {
throw new \Exception('No resource to export');
}
$workspace = $nodes[0]->getWorkspace();
$archive = $this->transferManager->exportResources($workspace, $nodes);
$fileName = $workspace->getCode() . '.zip';
$mimeType = 'application/zip';
$response = new StreamedResponse();
$response->setCallBack(function () use($archive) {
readfile($archive);
});
$response->headers->set('Content-Transfer-Encoding', 'octet-stream');
$response->headers->set('Content-Type', 'application/force-download');
$response->headers->set('Content-Disposition', 'attachment; filename=' . urlencode($fileName));
$response->headers->set('Content-Type', $mimeType);
$response->headers->set('Content-Length', filesize($archive));
$response->headers->set('Connection', 'close');
return $response;
}
示例11: exportEvent
private function exportEvent($workspace = null)
{
$file = $this->agendaManager->export();
$response = new StreamedResponse();
$response->setCallBack(function () use($file) {
readfile($file);
});
$name = $workspace ? $workspace->getName() : 'desktop';
$response->headers->set('Content-Transfer-Encoding', 'octet-stream');
$response->headers->set('Content-Type', 'application/force-download');
$response->headers->set('Content-Disposition', 'attachment; filename=' . $name . '.ics');
$response->headers->set('Content-Type', ' text/calendar');
$response->headers->set('Connection', 'close');
return $response;
}
示例12: exportAction
/**
* @EXT\Route(
* "/export/{format}/from/{from}/to/{to}/isFree/{isFree}/search/{search}",
* name="formalibre_export_invoice",
* defaults={"format"="xls", "search" = ""}
* )
* @Security("has_role('ROLE_ADMIN')")
*
* @return Response
*/
public function exportAction($format, $search, $isFree, $from, $to)
{
//the admin is the only one able to do this.
if (!$this->authorization->isGranted('ROLE_ADMIN')) {
throw new \AccessDeniedException();
}
$boolFree = $isFree === "true" ? true : false;
$invoices = $boolFree ? $this->invoiceManager->getInvoices(true, $search, $from, $to, false) : $this->invoiceManager->getFree($search, $from, $to, false);
$file = $this->invoiceManager->export($invoices, $this->container->get('claroline.exporter.' . $format));
$response = new StreamedResponse();
$response->setCallBack(function () use($file) {
readfile($file);
});
$response->headers->set('Content-Transfer-Encoding', 'octet-stream');
$response->headers->set('Content-Type', 'application/force-download');
$response->headers->set('Content-Disposition', 'attachment; filename=users.' . $format);
switch ($format) {
case 'csv':
$response->headers->set('Content-Type', 'text/csv');
break;
case 'xls':
$response->headers->set('Content-Type', 'application/vnd.ms-excel');
break;
}
$response->headers->set('Connection', 'close');
return $response;
}
示例13: exportCsvSessionEventUsersAction
/**
* @EXT\Route(
* "/api/session/event/{sessionEvent}/users/type/{type}/csv/export",
* name="api_get_session_event_users_csv_export",
* options = {"expose"=true}
* )
* @EXT\ParamConverter("user", converter="current_user")
*/
public function exportCsvSessionEventUsersAction(SessionEvent $sessionEvent, $type)
{
$exportType = intval($type);
$users = [];
if ($exportType === 1 || $exportType === 3) {
$users['participants'] = $this->cursusManager->getUsersBySessionEventAndStatus($sessionEvent, SessionEventUser::REGISTERED);
}
if ($exportType === 2 || $exportType === 3) {
$users['trainers'] = $sessionEvent->getTutors();
}
$response = new StreamedResponse();
$response->setCallBack(function () use($users) {
$handle = fopen('php://output', 'r+');
if (count($users) === 2) {
fwrite($handle, $this->translator->trans('trainers', [], 'cursus') . PHP_EOL);
}
if (isset($users['trainers'])) {
foreach ($users['trainers'] as $user) {
fwrite($handle, implode(';', [$user->getFirstName(), $user->getLastName()]) . PHP_EOL);
}
}
if (count($users) === 2) {
fwrite($handle, PHP_EOL);
fwrite($handle, $this->translator->trans('participants', [], 'cursus') . PHP_EOL);
}
if (isset($users['participants'])) {
foreach ($users['participants'] as $user) {
fwrite($handle, implode(';', [$user->getFirstName(), $user->getLastName()]) . PHP_EOL);
}
}
fclose($handle);
});
$fileName = $sessionEvent->getName();
if ($exportType === 1) {
$fileName .= '[' . $this->translator->trans('participants', [], 'cursus') . ']';
} elseif ($exportType === 2) {
$fileName .= '[' . $this->translator->trans('trainers', [], 'cursus') . ']';
}
$response->headers->set('Content-Transfer-Encoding', 'octet-stream');
$response->headers->set('Content-Type', 'application/force-download');
$response->headers->set('Content-Disposition', 'attachment; filename=' . $fileName . '.csv');
$response->headers->set('Content-Type', 'text/csv');
$response->headers->set('Connection', 'close');
return $response;
}