'csv'])] public function socialIssueList(Request $request, string $_format = 'csv'): StreamedResponse { if (!$this->security->isGranted('ROLE_ADMIN')) { throw new AccessDeniedHttpException('Only ROLE_ADMIN can export this list'); } $socialIssues = $this->socialIssueRepository->findAll(); $socialIssues = array_map(function ($issue) { return [ 'id' => $issue->getId(), 'title' => $this->socialIssueRender->renderString($issue, []), 'ordering' => $issue->getOrdering(), 'desactivationDate' => $issue->getDesactivationDate(), ]; }, $socialIssues); $csv = Writer::createFromPath('php://temp', 'r+'); $csv->insertOne( array_map( fn (string $e) => $this->translator->trans($e), [ 'Id', 'Title', 'Ordering', 'goal.desactivationDate', ] ) ); $csv->addFormatter(fn (array $row) => null !== ($row['desactivationDate'] ?? null) ? array_merge($row, ['desactivationDate' => $row['desactivationDate']->format('Y-m-d')]) : $row); $csv->insertAll($socialIssues); return new StreamedResponse( function () use ($csv) { foreach ($csv->chunk(1024) as $chunk) { echo $chunk; flush(); } }, Response::HTTP_OK, [ 'Content-Encoding' => 'none', 'Content-Type' => 'text/csv; charset=UTF-8', 'Content-Disposition' => 'attachment; users.csv', ] ); } }