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