<?php
namespace App\EventSubscriber;
use App\Event\ActionErrorEvent;
use App\Event\ActionFormEvent;
use App\Service\FormActionSetManager;
use Exception;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ActionSubscriber implements EventSubscriberInterface
{
/** @var FormActionSetManager $formActionSetManager */
private $formActionSetManager;
/**
* @param FormActionSetManager $formActionSetManager
*/
public function __construct(FormActionSetManager $formActionSetManager)
{
$this->formActionSetManager = $formActionSetManager;
}
/**
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
ActionErrorEvent::KEY => 'onActionError',
ActionFormEvent::KEY => 'onAppEventsForm'
];
}
/**
* @param ActionErrorEvent $event
* @return void
*/
public function onActionError(ActionErrorEvent $event)
{
// TODO: generar log de error o enviar a un email determinado
}
/**
* @param ActionFormEvent $event
* @return void
* @throws Exception
*/
public function onAppEventsForm(ActionFormEvent $event)
{
$this->formActionSetManager
->setForm($event->getForm())
->setLead($event->getFormLead())
->executeActionSets($event->getName())
;
}
}