src/EventSubscriber/Savills/WorkValidationRequestSubscriber.php line 20

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