src/Component/ExternalIntegration/Integration/Tigris/ExposeVacancyToTigrisOnExternalVacancyUperted.php line 34

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Component\ExternalIntegration\Integration\Tigris;
  4. use App\Component\ExternalIntegration\Integration\Tigris\Configuration\ConfigEnum;
  5. use App\Component\ExternalIntegration\Manager\ExternalVacancyCreated;
  6. use App\Component\ExternalIntegration\Manager\ExternalVacancyUpdated;
  7. use App\Writer\TigrisWriter;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Contracts\EventDispatcher\Event;
  10. class ExposeVacancyToTigrisOnExternalVacancyUperted implements EventSubscriberInterface
  11. {
  12.     public function __construct(
  13.         private readonly TigrisWriter $tigrisWriter
  14.     ) {
  15.     }
  16.     public static function getSubscribedEvents(): array
  17.     {
  18.         return [
  19.             ExternalVacancyCreated::class => 'exposeOnCreate',
  20.             ExternalVacancyUpdated::class => 'exposeOnUpdate',
  21.         ];
  22.     }
  23.     public function exposeOnCreate(ExternalVacancyCreated $event): void
  24.     {
  25.         $this->expose($event);
  26.     }
  27.     public function exposeOnUpdate(ExternalVacancyUpdated $event): void
  28.     {
  29.         $this->expose($event);
  30.     }
  31.     private function expose(Event $event): void
  32.     {
  33.         /** @var ExternalVacancyUpdated|ExternalVacancyCreated $event */
  34.         $vacancy $event->getVacancy();
  35.         if ($vacancy->getExternalReference() !== ConfigEnum::EXTERNAL_INTEGRATION_REFERENCE->value) {
  36.             return;
  37.         }
  38.         if (null === $vacancy->getExternalId()) {
  39.             return;
  40.         }
  41.         $this->tigrisWriter->exposeVacancyToTigris($vacancy$event->getTransaction());
  42.     }
  43. }