<?php
namespace App\EventListener;
use App\Event\ApplicantEvent;
use App\Writer\OtysWriter;
use Doctrine\ORM\EntityManagerInterface;
use Flagception\Manager\FeatureManagerInterface;
class OtysApplicantEventListener
{
/**
* @var EntityManagerInterface
*/
private $entityManager;
/**
* @var FeatureManagerInterface
*/
private $featureManager;
/**
* @var OtysWriter
*/
private $otysWriter;
public function __construct(
EntityManagerInterface $entityManager,
FeatureManagerInterface $featureManager,
OtysWriter $otysWriter
) {
$this->entityManager = $entityManager;
$this->featureManager = $featureManager;
$this->otysWriter = $otysWriter;
}
public function applicantSubmit(ApplicantEvent $applicantEvent)
{
if (!$this->featureManager->isActive(FeatureFlagListener::FEATURE_OTYS_APPLICANT_SEND)) {
return;
}
$applicant = $applicantEvent->getApplicant();
$form = $applicantEvent->getForm();
$file = $form->has('CVFile') ? $form['CVFile']->getData() : null;
$this->otysWriter->postApplicant($applicant, $file);
}
}