<?php
namespace App\EventListener;
use App\Event\ApplicantEvent;
use App\Manager\DigivotionManager;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Flagception\Manager\FeatureManagerInterface;
class DigivotionEventListener
{
protected DigivotionManager $digivotionManager;
private EntityManagerInterface $entityManager;
private FeatureManagerInterface $featureManager;
/**
* DigivotionEventListener constructor.
*/
public function __construct(
DigivotionManager $digivotionManager,
EntityManagerInterface $entityManager,
FeatureManagerInterface $featureManager
) {
$this->digivotionManager = $digivotionManager;
$this->entityManager = $entityManager;
$this->featureManager = $featureManager;
}
/**
* @throws Exception
*/
public function onApplicantSubmit(ApplicantEvent $applicantEvent)
{
if (!$this->featureManager->isActive(FeatureFlagListener::FEATURE_DIGIVOTION)) {
return;
}
$applicant = $applicantEvent->getApplicant();
$this->digivotionManager->postApplicant($applicant);
$this->entityManager->persist($applicant);
$this->entityManager->flush();
}
}