<?php
namespace App\EventSubscriber;
use ApiPlatform\Core\EventListener\EventPriorities;
use App\Model\InterventionRequest\PostInterventionRequest;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ViewEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class InterventionRequestSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
KernelEvents::VIEW => ['getPostInterventionRequest', EventPriorities::PRE_WRITE],
];
}
public function getPostInterventionRequest(ViewEvent $event)
{
$postInterventionRequest = $event->getControllerResult();
if ($postInterventionRequest instanceof PostInterventionRequest) {
$postInterventionRequest->setId((int) $event->getRequest()->attributes->get('id'));
}
$event->setControllerResult($postInterventionRequest);
}
}