src/EventListener/KernelListener.php line 43

Open in your IDE?
  1. <?php
  2. namespace Eadmin\EventListener;
  3. use Eadmin\Http\EADResponse;
  4. use Eadmin\Error\ActionInvalidException;
  5. use Eadmin\Error\FieldException;
  6. use Eadmin\Error\EADException;
  7. use Eadmin\Services\GeneralService;
  8. use Symfony\Component\HttpKernel\Event\RequestEvent;
  9. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  10. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  11. use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\HttpFoundation\RedirectResponse;
  14. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  15. use Doctrine\DBAL\Exception\TableNotFoundException;
  16. use Doctrine\DBAL\Exception\InvalidFieldNameException;
  17. class KernelListener
  18. {
  19.     /**
  20.      *@var UrlGeneratorInterface
  21.      */
  22.     protected $router;
  23.     /**
  24.      *@var GeneralService
  25.      */
  26.     protected $generalService;
  27.     /**
  28.      * @param UrlGeneratorInterface Router
  29.      * @param GeneralService generalService
  30.      */
  31.     public function __construct(UrlGeneratorInterface $router
  32.                                 GeneralService $generalService)
  33.     {
  34.         $this->router $router;
  35.         $this->generalService $generalService;
  36.     }
  37.     public function onKernelRequest(RequestEvent $event)
  38.     {   
  39.     }
  40.     public function onKernelException(ExceptionEvent $event)
  41.     {
  42.         $exception $event->getThrowable();
  43.         if($exception instanceof EADException){
  44.             $eadResponse = new EADResponse(
  45.                 $exception->getData(),
  46.                 $exception->getCode(),
  47.                 $exception->getHeaders()
  48.             );
  49.             $event->setResponse($eadResponse->getResponse());
  50.         }else if(
  51.             $exception instanceof NotFoundHttpException || 
  52.             $exception instanceof MethodNotAllowedHttpException
  53.         ) {
  54.             $route 'notFound';
  55.             if ($route === $event->getRequest()->get('_route')) {
  56.                 return;
  57.             }
  58.             $url $this->router->generate($route);
  59.             $response = new RedirectResponse($url);
  60.             $event->setResponse($response);
  61.         }else if (
  62.             $exception instanceof TableNotFoundException ||
  63.             $exception instanceof InvalidFieldNameException
  64.         ){
  65.         }
  66.     }