src/EventListener/FormBuilderEventListener.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Entity\Vacancy;
  4. use App\Event\EntityPersistedEvent;
  5. use App\Generator\Invoice;
  6. use Flagception\Manager\FeatureManagerInterface;
  7. use League\Flysystem\FileExistsException;
  8. class FormBuilderEventListener
  9. {
  10.     /**
  11.      * @var FeatureManagerInterface
  12.      */
  13.     private $featureManager;
  14.     /**
  15.      * @var Invoice
  16.      */
  17.     private $generator;
  18.     /**
  19.      * FormBuilderEventListener constructor.
  20.      */
  21.     public function __construct(FeatureManagerInterface $featureManagerInvoice $generator)
  22.     {
  23.         $this->featureManager $featureManager;
  24.         $this->generator $generator;
  25.     }
  26.     /**
  27.      * @throws FileExistsException
  28.      */
  29.     public function onPersist(EntityPersistedEvent $event)
  30.     {
  31.         if (Vacancy::class === \get_class($event->getEntity())) {
  32.             /** @var Vacancy $vacancy */
  33.             $vacancy $event->getEntity();
  34.             if ($this->featureManager->isActive('feature_vacancy_invoice') &&
  35.                 $vacancy->isFeatured() &&
  36.                 !$vacancy->getInvoice()
  37.             ) {
  38.                 $this->generator->generateInvoiceForVacancy($vacancy);
  39.             }
  40.         }
  41.     }
  42. }