src/EventSubscriber/ActionSubscriber.php line 49

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Event\ActionErrorEvent;
  4. use App\Event\ActionFormEvent;
  5. use App\Service\FormActionSetManager;
  6. use Exception;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class ActionSubscriber implements EventSubscriberInterface
  9. {
  10.     /** @var FormActionSetManager $formActionSetManager */
  11.     private $formActionSetManager;
  12.     /**
  13.      * @param FormActionSetManager $formActionSetManager
  14.      */
  15.     public function __construct(FormActionSetManager $formActionSetManager)
  16.     {
  17.         $this->formActionSetManager $formActionSetManager;
  18.     }
  19.     /**
  20.      * @return string[]
  21.      */
  22.     public static function getSubscribedEvents(): array
  23.     {
  24.         return [
  25.             ActionErrorEvent::KEY => 'onActionError',
  26.             ActionFormEvent::KEY => 'onAppEventsForm'
  27.         ];
  28.     }
  29.     /**
  30.      * @param ActionErrorEvent $event
  31.      * @return void
  32.      */
  33.     public function onActionError(ActionErrorEvent $event)
  34.     {
  35.         // TODO: generar log de error o enviar a un email determinado
  36.     }
  37.     /**
  38.      * @param ActionFormEvent $event
  39.      * @return void
  40.      * @throws Exception
  41.      */
  42.     public function onAppEventsForm(ActionFormEvent $event)
  43.     {
  44.         $this->formActionSetManager
  45.             ->setForm($event->getForm())
  46.             ->setLead($event->getFormLead())
  47.             ->executeActionSets($event->getName())
  48.         ;
  49.     }
  50. }