<?php
// src/EventListener/ExceptionListener.php
namespace App\EventListener;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\TerminateEvent;
class FileDownloadListener
{
public function onKernelTerminate(TerminateEvent $event)
{
$request = $event->getRequest();
$response = $event->getResponse();
$routeName = $request->attributes->get('_route');
if ($response->getStatusCode() === Response::HTTP_OK && $routeName == 'download-export') {
unlink($response->getFile()->getPathname());
}
}
}