src/EventSubscriber/InsuredSubmitInsurersSubscriber.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use ApiPlatform\Core\EventListener\EventPriorities;
  4. use App\Entity\InsuredSubmitInsurers;
  5. use App\Message\SendInsuredSubmitInsurers;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\HttpFoundation\Request;
  8. // use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  9. use Symfony\Component\HttpKernel\Event\ViewEvent;
  10. use Symfony\Component\HttpKernel\KernelEvents;
  11. use Symfony\Component\Messenger\MessageBusInterface;
  12. // use App\Entity\User;
  13. final class InsuredSubmitInsurersSubscriber implements EventSubscriberInterface
  14. {
  15.     public function __construct(
  16.         // TokenStorageInterface $tokenStorage,
  17.         MessageBusInterface $messageBus,
  18.     ) {
  19.         // $this->tokenStorage = $tokenStorage;
  20.         $this->messageBus $messageBus;
  21.     }
  22.     public static function getSubscribedEvents(): array
  23.     {
  24.         return [
  25.             KernelEvents::VIEW => [
  26.                 ['sendInsuredSubmitInsurers'EventPriorities::POST_WRITE],
  27.             ],
  28.         ];
  29.     }
  30.     public function sendInsuredSubmitInsurers(ViewEvent $event): void
  31.     {
  32.         $insuredSubmitInsurers $event->getControllerResult();
  33.         $method $event->getRequest()->getMethod();
  34.         if (!$insuredSubmitInsurers instanceof InsuredSubmitInsurers || Request::METHOD_POST !== $method) {
  35.             return;
  36.         }
  37.         // $token = $this->tokenStorage->getToken();
  38.         // if (!$token) {
  39.         //     return;
  40.         // }
  41.         // $user = $token->getUser();
  42.         // if (!$user instanceof User) {
  43.         //     return;
  44.         // }
  45.         $message = new SendInsuredSubmitInsurers();
  46.         $message->setInsuredSubmitInsurersId($insuredSubmitInsurers->getId());
  47.         $this->messageBus->dispatch($message);
  48.     }
  49. }