lib/DatatableBundle/src/Controller/EventStreamController.php line 27

Open in your IDE?
  1. <?php
  2. namespace EchoNumeric\DatatableBundle\src\Controller;
  3. use http\Client\Response;
  4. use Symfony\Component\HttpFoundation\JsonResponse;
  5. use Symfony\Component\HttpFoundation\RequestStack;
  6. class EventStreamController
  7. {
  8. private RequestStack $requestStack;
  9. public function __construct( RequestStack $requestStack )
  10. {
  11. $this->requestStack = $requestStack;
  12. }
  13. /**
  14. * @return JsonResponse
  15. */
  16. public function endExport(): JsonResponse
  17. {
  18. ini_set('memory_limit', '-1');
  19. $session = $this->requestStack->getSession();
  20. $isExporting = $session->get('export_datatable');
  21. if(ob_get_length() > 0) {
  22. ob_clean();
  23. }
  24. header( "Cache-Control: no-cache" );
  25. header( "Content-Type: text/event-stream" );
  26. echo "event: ping\n";
  27. if ( $isExporting ) {
  28. echo 'data: file not sent';
  29. } else {
  30. echo 'data: file sent';
  31. }
  32. echo "\n\n";
  33. ob_end_flush();
  34. flush();
  35. return new JsonResponse([], \Symfony\Component\HttpFoundation\Response::HTTP_OK);
  36. }
  37. }