本文整理汇总了PHP中Symfony\Component\HttpFoundation\StreamedResponse::prepare方法的典型用法代码示例。如果您正苦于以下问题:PHP StreamedResponse::prepare方法的具体用法?PHP StreamedResponse::prepare怎么用?PHP StreamedResponse::prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\StreamedResponse
的用法示例。
在下文中一共展示了StreamedResponse::prepare方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testPrepareWithHeadRequest
public function testPrepareWithHeadRequest()
{
$response = new StreamedResponse(function () {
echo 'foo';
});
$request = Request::create('/', 'HEAD');
$response->prepare($request);
}
示例2: testPrepareWithCacheHeaders
public function testPrepareWithCacheHeaders()
{
$response = new StreamedResponse(function () {
echo 'foo';
}, 200, array('Cache-Control' => 'max-age=600, public'));
$request = Request::create('/', 'GET');
$response->prepare($request);
$this->assertEquals('max-age=600, public', $response->headers->get('Cache-Control'));
}
示例3: testPrepareWith10Protocol
public function testPrepareWith10Protocol()
{
$response = new StreamedResponse(function () {
echo 'foo';
});
$request = Request::create('/');
$request->server->set('SERVER_PROTOCOL', '1.0');
$response->prepare($request);
$this->assertEquals('1.0', $response->getProtocolVersion());
$this->assertNull($response->headers->get('Transfer-Encoding'));
$this->assertEquals('no-cache, private', $response->headers->get('Cache-Control'));
}
示例4: exportAllToCSVAction
/**
* @Route("/export", name="area_edk_participant_export_all")
*/
public function exportAllToCSVAction(Request $request)
{
$repository = $this->get(self::REPOSITORY_NAME);
$area = $this->getMembership()->getItem();
$response = new StreamedResponse(function () use($repository, $area) {
$repository->exportToCSVStream($this->getTranslator(), $area);
});
$response->headers->set('Content-Type', 'text/csv');
$response->headers->set('Cache-Control', '');
$response->headers->set('Last-Modified', gmdate('D, d M Y H:i:s'));
$contentDisposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'participants-all-routes.csv');
$response->headers->set('Content-Disposition', $contentDisposition);
$response->prepare($request);
return $response;
}
示例5: downloadAction
/**
* @Route("/file_manager/download", name="spliced_cms_admin_file_manager_download")
* @Template()
*/
public function downloadAction()
{
$this->loadContext();
$file = $this->file;
if (is_null($this->file) || false === $this->file->getRealPath()) {
$this->get('session')->getFlashBag()->add('error', 'File Not Found');
return $this->redirect($this->generateUrl('spliced_cms_admin_file_manager', array('dir' => str_replace($this->baseDir->getRealPath(), '', $this->dir->getRealPath()))));
}
$file = $this->file;
$response = new StreamedResponse(function () use($file) {
echo $file->getContents();
});
$info = new \finfo(FILEINFO_MIME_TYPE);
$response->headers->set('Content-Type', $info->file($file->getRealPath()));
$response->headers->set('Cache-Control', '');
$response->headers->set('Content-Length', $file->getSize());
$response->headers->set('Last-Modified', gmdate('D, d M Y H:i:s'));
$response->headers->set('Content-Disposition', $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $file->getFilename()));
$response->prepare($this->get('request'));
return $response;
}
示例6: downloadcsvAction
/**
* route to download CSV file
* @param string $slug
* @param mixed $group
*/
public function downloadcsvAction($slug, $group = false)
{
//$param = $this->getConfiguration($slug, $group);
$repository = $this->getDoctrine()->getRepository('FgmsSurveyBundle:Questionnaire');
$sluggroup = $group != false ? $group : '';
$query = $repository->createQueryBuilder('q')->where('q.slug = :slug AND q.sluggroup = :sluggroup')->setParameters(array('slug' => $slug, 'sluggroup' => $sluggroup))->orderBy('q.createDate', 'ASC')->getQuery();
$response = new StreamedResponse();
$response->setCallback(function () use($query) {
$handle = fopen('php://output', 'w+');
fputcsv($handle, array('Survey#', 'Date', 'Time', 'Group', 'Property', 'Room', 'Q1', 'Q2', 'Q3', 'Q4', 'Q5', 'Q6', 'Q7', 'Q8', 'Q9', 'Q10', 'Q11', 'Q12', 'Q13', 'Q14', 'Q15'), ',');
foreach ($query->getResult() as $item) {
fputcsv($handle, array($item->getId(), $item->getCreateDate()->format('F j, Y'), $item->getCreateDate()->format('h:i A'), $item->getSluggroup(), $item->getSlug(), $item->getRoomNumber(), $item->getQuestion1(), $item->getQuestion2(), $item->getQuestion3(), $item->getQuestion4(), $item->getQuestion5(), $item->getQuestion6(), $item->getQuestion7(), $item->getQuestion8(), $item->getQuestion9(), $item->getQuestion10(), $item->getQuestion11(), $item->getQuestion12(), $item->getQuestion13(), $item->getQuestion14(), $item->getQuestion15()));
}
fclose($handle);
});
$response->setStatusCode(200);
$response->headers->set('Content-Type', 'application/force-download');
$response->headers->set('Content-Type', 'text/csv; charset=utf-8');
$response->headers->set('Content-Disposition', $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $slug . '-export.csv'));
$response->prepare($this->request);
return $response;
}
示例7: importAction
public function importAction(Request $request)
{
$filepath = $this->checkReportFile($request);
if ($filepath instanceof Response) {
return $filepath;
}
$filemark = $request->get('filemark');
$types = array('orders', 'employes', 'calls');
if (!($type = $request->get('type')) || !in_array($type, $types, true)) {
return $this->redirect($this->generateUrl('taxi_prize_importer_confirm', array('filemark' => $filemark)));
}
// "Переезд" на новый импортер
if ($type === 'employes') {
$type = 'employes2';
}
$namespace = '\\TaxiPrize\\ImporterBundle\\Import\\Importer\\';
$importer_class = $namespace . ucfirst($type) . 'Importer';
$source = new Import\ExcelSource($filepath);
/** @var Import\AbstractImporter */
$importer = new $importer_class($source);
// Checking for header mismatch
$header_mismatch = $importer->getHeaderMismatch();
if (!empty($header_mismatch)) {
return $this->render('TaxiPrizeImporterBundle:Default:import-fail.html.php', array('error_header_mismatch' => $header_mismatch, 'expected_header' => $importer->getExpectedHeader()));
}
$controller = $this;
$callb = function () use($controller, $importer) {
$controller->importOutput($importer);
};
$response = new StreamedResponse($callb);
return $response->prepare($request);
// return $this->render('TaxiPrizeImporterBundle:Default:import.html.php', array(
// 'result' => $result,
// 'not_imported_file_link' => $not_imported_file_link,
// ));
}