src/EventSubscriber/HROfficeEventSubscriber.php line 43

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Event\AbstractJobAlertEvent;
  4. use App\Event\JobAlertCreatedEvent;
  5. use App\EventListener\FeatureFlagListener;
  6. use App\Util\HROffice;
  7. use Exception;
  8. use Flagception\Manager\FeatureManagerInterface;
  9. use Psr\Log\LoggerInterface;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. class HROfficeEventSubscriber implements EventSubscriberInterface
  12. {
  13.     protected FeatureManagerInterface $featureManager;
  14.     protected HROffice $hrOffice;
  15.     protected LoggerInterface $hrOfficeLogger;
  16.     /**
  17.      * HROfficeEventSubscriber constructor.
  18.      */
  19.     public function __construct(
  20.         FeatureManagerInterface $featureManager,
  21.         HROffice $hrOffice,
  22.         LoggerInterface $hrOfficeLogger
  23.     ) {
  24.         $this->featureManager $featureManager;
  25.         $this->hrOffice $hrOffice;
  26.         $this->hrOfficeLogger $hrOfficeLogger;
  27.     }
  28.     /**
  29.      * {@inheritDoc}
  30.      */
  31.     public static function getSubscribedEvents()
  32.     {
  33.         return [
  34.             JobAlertCreatedEvent::class => 'postJobAlert',
  35.         ];
  36.     }
  37.     public function postJobAlert(AbstractJobAlertEvent $event)
  38.     {
  39.         if (
  40.             !$this->featureManager->isActive(FeatureFlagListener::FEATURE_HR_OFFICE) ||
  41.             !$this->featureManager->isActive(FeatureFlagListener::FEATURE_HR_OFFICE_JOBALERT)
  42.         ) {
  43.             return;
  44.         }
  45.         try {
  46.             $this->hrOffice->postJobAlert($event->getJobAlert());
  47.         } catch (Exception $exception) {
  48.             $this->hrOfficeLogger->critical($exception->getMessage(), [
  49.                 'jobalert_id' => $event->getJobAlert()->getId(),
  50.             ]);
  51.         }
  52.     }
  53. }