<?php
namespace EchoNumeric\DatatableBundle\src\Controller;
use http\Client\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RequestStack;
class EventStreamController
{
private RequestStack $requestStack;
public function __construct( RequestStack $requestStack )
{
$this->requestStack = $requestStack;
}
/**
* @return JsonResponse
*/
public function endExport(): JsonResponse
{
ini_set('memory_limit', '-1');
$session = $this->requestStack->getSession();
$isExporting = $session->get('export_datatable');
if(ob_get_length() > 0) {
ob_clean();
}
header( "Cache-Control: no-cache" );
header( "Content-Type: text/event-stream" );
echo "event: ping\n";
if ( $isExporting ) {
echo 'data: file not sent';
} else {
echo 'data: file sent';
}
echo "\n\n";
ob_end_flush();
flush();
return new JsonResponse([], \Symfony\Component\HttpFoundation\Response::HTTP_OK);
}
}