src/Subscriber/RequestSubscriber.php line 18

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Subscriber;
  4. use App\Exception\Cinema\MalformedCinemaIdentifierException;
  5. use App\Exception\Event\MalformedEventIdentifierException;
  6. use App\Exception\Order\MalformedOrderIdentifierException;
  7. use App\Exception\Screening\MalformedScreeningIdentifierException;
  8. use Ramsey\Uuid\Uuid;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. use Symfony\Component\HttpKernel\Event\RequestEvent;
  11. use Symfony\Component\HttpKernel\KernelEvents;
  12. class RequestSubscriber implements EventSubscriberInterface
  13. {
  14.     public function onKernelRequest(RequestEvent $event)
  15.     {
  16.         $request $event->getRequest();
  17.         if ($request->attributes->has('cinemaId') && !Uuid::isValid($request->attributes->get('cinemaId'))) {
  18.             throw new MalformedCinemaIdentifierException();
  19.         }
  20.         if ($request->attributes->has('screeningId') && !Uuid::isValid($request->attributes->get('screeningId'))) {
  21.             throw new MalformedScreeningIdentifierException();
  22.         }
  23.         if ($request->attributes->get('orderId') && !Uuid::isValid($request->attributes->get('orderId'))) {
  24.             throw new MalformedOrderIdentifierException();
  25.         }
  26.         if ($request->query->get('cinemaId') && !Uuid::isValid($request->query->get('cinemaId'))) {
  27.             throw new MalformedCinemaIdentifierException();
  28.         }
  29.         if ($request->attributes->has('eventId') && !Uuid::isValid($request->attributes->get('eventId'))) {
  30.             throw new MalformedEventIdentifierException();
  31.         }
  32.     }
  33.     public static function getSubscribedEvents()
  34.     {
  35.         return [
  36.             KernelEvents::REQUEST => [['onKernelRequest'19]],
  37.         ];
  38.     }
  39. }