<?php
declare(strict_types=1);
namespace App\Subscriber;
use App\Exception\Cinema\MalformedCinemaIdentifierException;
use App\Exception\Event\MalformedEventIdentifierException;
use App\Exception\Order\MalformedOrderIdentifierException;
use App\Exception\Screening\MalformedScreeningIdentifierException;
use Ramsey\Uuid\Uuid;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class RequestSubscriber implements EventSubscriberInterface
{
public function onKernelRequest(RequestEvent $event)
{
$request = $event->getRequest();
if ($request->attributes->has('cinemaId') && !Uuid::isValid($request->attributes->get('cinemaId'))) {
throw new MalformedCinemaIdentifierException();
}
if ($request->attributes->has('screeningId') && !Uuid::isValid($request->attributes->get('screeningId'))) {
throw new MalformedScreeningIdentifierException();
}
if ($request->attributes->get('orderId') && !Uuid::isValid($request->attributes->get('orderId'))) {
throw new MalformedOrderIdentifierException();
}
if ($request->query->get('cinemaId') && !Uuid::isValid($request->query->get('cinemaId'))) {
throw new MalformedCinemaIdentifierException();
}
if ($request->attributes->has('eventId') && !Uuid::isValid($request->attributes->get('eventId'))) {
throw new MalformedEventIdentifierException();
}
}
public static function getSubscribedEvents()
{
return [
KernelEvents::REQUEST => [['onKernelRequest', 19]],
];
}
}