public function testPrepareWithHeadRequest() { $response = new StreamedResponse(function () { echo 'foo'; }); $request = Request::create('/', 'HEAD'); $response->prepare($request); }
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')); }
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')); }
/** * @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; }
/** * @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; }
/** * 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; }
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, // )); }