<?php
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;
class NotFoundSubscriber implements EventSubscriberInterface
{
private $twig;
public function __construct(Environment $twig)
{
$this->twig = $twig;
}
public function onKernelException(ExceptionEvent $event)
{
$exception = $event->getThrowable();
/*
if ($exception instanceof NotFoundHttpException) {
// Ici, tu peux personnaliser selon le chemin
$response = new Response(
$this->twig->render('error/entity_not_found.html.twig', [
'type' => null,
'id' => null,
]),
404
);
$event->setResponse($response);
}
*/
}
public static function getSubscribedEvents()
{
return [
'kernel.exception' => 'onKernelException',
];
}
}