<?php
namespace App\EventListener;
use App\Entity\Vacancy;
use App\Event\EntityPersistedEvent;
use App\Generator\Invoice;
use Flagception\Manager\FeatureManagerInterface;
use League\Flysystem\FileExistsException;
class FormBuilderEventListener
{
/**
* @var FeatureManagerInterface
*/
private $featureManager;
/**
* @var Invoice
*/
private $generator;
/**
* FormBuilderEventListener constructor.
*/
public function __construct(FeatureManagerInterface $featureManager, Invoice $generator)
{
$this->featureManager = $featureManager;
$this->generator = $generator;
}
/**
* @throws FileExistsException
*/
public function onPersist(EntityPersistedEvent $event)
{
if (Vacancy::class === \get_class($event->getEntity())) {
/** @var Vacancy $vacancy */
$vacancy = $event->getEntity();
if ($this->featureManager->isActive('feature_vacancy_invoice') &&
$vacancy->isFeatured() &&
!$vacancy->getInvoice()
) {
$this->generator->generateInvoiceForVacancy($vacancy);
}
}
}
}