src/EventSubscriber/InterventionRequestSubscriber.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use ApiPlatform\Core\EventListener\EventPriorities;
  4. use App\Model\InterventionRequest\PostInterventionRequest;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\Event\ViewEvent;
  7. use Symfony\Component\HttpKernel\KernelEvents;
  8. class InterventionRequestSubscriber implements EventSubscriberInterface
  9. {
  10.     public static function getSubscribedEvents()
  11.     {
  12.         return [
  13.             KernelEvents::VIEW => ['getPostInterventionRequest'EventPriorities::PRE_WRITE],
  14.         ];
  15.     }
  16.     public function getPostInterventionRequest(ViewEvent $event)
  17.     {
  18.         $postInterventionRequest $event->getControllerResult();
  19.         if ($postInterventionRequest instanceof PostInterventionRequest) {
  20.             $postInterventionRequest->setId((int) $event->getRequest()->attributes->get('id'));
  21.         }
  22.         $event->setControllerResult($postInterventionRequest);
  23.     }
  24. }