<?php
namespace App\EventListener;
use App\Event\ApplicantEvent;
use App\Writer\SolutionsFactoryWriter;
use Exception;
use Flagception\Manager\FeatureManagerInterface;
class SolutionsFactoryApplicantEventListener
{
private FeatureManagerInterface $featureManager;
private SolutionsFactoryWriter $solutionsFactoryWriter;
public function __construct(FeatureManagerInterface $featureManager, SolutionsFactoryWriter $solutionsFactoryWriter)
{
$this->featureManager = $featureManager;
$this->solutionsFactoryWriter = $solutionsFactoryWriter;
}
/**
* @throws Exception
*/
public function applicantSubmit(ApplicantEvent $applicantEvent): void
{
if (!$this->featureManager->isActive(FeatureFlagListener::FEATURE_SOLUTIONS_FACTORY)) {
return;
}
$cvFile = null;
if (!empty($applicantEvent->getForm()['CVFile'])) {
$cvFile = $applicantEvent->getForm()['CVFile']->getData();
}
$motivationFile = null;
if (!empty($applicantEvent->getForm()['motivationFile'])) {
$motivationFile = $applicantEvent->getForm()['motivationFile']->getData();
}
$this->solutionsFactoryWriter->createApplicant($applicantEvent->getApplicant(), $cvFile, $motivationFile);
}
}