src/EventListener/FileDownloadListener.php line 11

Open in your IDE?
  1. <?php
  2. // src/EventListener/ExceptionListener.php
  3. namespace App\EventListener;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpKernel\Event\TerminateEvent;
  6. class FileDownloadListener
  7. {
  8.     public function onKernelTerminate(TerminateEvent $event)
  9.     {
  10.         $request $event->getRequest();
  11.         $response $event->getResponse();
  12.         $routeName $request->attributes->get('_route');
  13.         
  14.         if ($response->getStatusCode() === Response::HTTP_OK && $routeName == 'download-export') {
  15.             unlink($response->getFile()->getPathname());
  16.         }
  17.     }
  18. }