src/EventSubscriber/CompanySubscriber.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Entity\JobQueue;
  4. use App\Service\EsJobQueue;
  5. use App\Event\CompanyPostUpdateEvent;
  6. use App\Event\CompanyPostPersistEvent;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use App\Service\JobQueueAction\AttachCompanyToUserAction;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. class CompanySubscriber implements EventSubscriberInterface
  11. {
  12.     public function __construct(
  13.         private EntityManagerInterface $_em,
  14.         private EsJobQueue $esJobQueue
  15.     ) {
  16.     }
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [
  20.             CompanyPostPersistEvent::NAME => 'postPersist',
  21.             // CompanyPostUpdateEvent::NAME => 'postUpdate'
  22.         ];
  23.     }
  24.     public function postPersist(CompanyPostPersistEvent $event)
  25.     {
  26.         $data $event->getObject();
  27.         $payload = ['companyId' => $data->getId()];
  28.         $this->esJobQueue->create(
  29.             AttachCompanyToUserAction::NAME,
  30.             json_encode($payload),
  31.             JobQueue::PRIORITY_LOW
  32.         );
  33.     }
  34.     public function postUpdate(CompanyPostUpdateEvent $event)
  35.     {
  36.         // $data = $event->getObject();
  37.     }
  38. }