<?php
namespace App\EventSubscriber;
use App\Event\AbstractJobAlertEvent;
use App\Event\JobAlertCreatedEvent;
use App\EventListener\FeatureFlagListener;
use App\Util\HROffice;
use Exception;
use Flagception\Manager\FeatureManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class HROfficeEventSubscriber implements EventSubscriberInterface
{
protected FeatureManagerInterface $featureManager;
protected HROffice $hrOffice;
protected LoggerInterface $hrOfficeLogger;
/**
* HROfficeEventSubscriber constructor.
*/
public function __construct(
FeatureManagerInterface $featureManager,
HROffice $hrOffice,
LoggerInterface $hrOfficeLogger
) {
$this->featureManager = $featureManager;
$this->hrOffice = $hrOffice;
$this->hrOfficeLogger = $hrOfficeLogger;
}
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents()
{
return [
JobAlertCreatedEvent::class => 'postJobAlert',
];
}
public function postJobAlert(AbstractJobAlertEvent $event)
{
if (
!$this->featureManager->isActive(FeatureFlagListener::FEATURE_HR_OFFICE) ||
!$this->featureManager->isActive(FeatureFlagListener::FEATURE_HR_OFFICE_JOBALERT)
) {
return;
}
try {
$this->hrOffice->postJobAlert($event->getJobAlert());
} catch (Exception $exception) {
$this->hrOfficeLogger->critical($exception->getMessage(), [
'jobalert_id' => $event->getJobAlert()->getId(),
]);
}
}
}