Spaces:
No application file
No application file
File size: 1,993 Bytes
d2897cd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
<?php
declare(strict_types=1);
namespace Mautic\LeadBundle\Field\Dispatcher;
use Mautic\LeadBundle\Entity\LeadField;
use Mautic\LeadBundle\Exception\NoListenerException;
use Mautic\LeadBundle\Field\Event\AddColumnBackgroundEvent;
use Mautic\LeadBundle\Field\Event\UpdateColumnBackgroundEvent;
use Mautic\LeadBundle\Field\Exception\AbortColumnCreateException;
use Mautic\LeadBundle\Field\Exception\AbortColumnUpdateException;
use Mautic\LeadBundle\LeadEvents;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class FieldColumnBackgroundJobDispatcher
{
public function __construct(
private EventDispatcherInterface $dispatcher
) {
}
/**
* @throws AbortColumnCreateException
* @throws NoListenerException
*/
public function dispatchPreAddColumnEvent(LeadField $leadField): void
{
$action = LeadEvents::LEAD_FIELD_PRE_ADD_COLUMN_BACKGROUND_JOB;
if (!$this->dispatcher->hasListeners($action)) {
throw new NoListenerException('There is no Listener for this event');
}
$event = new AddColumnBackgroundEvent($leadField);
$this->dispatcher->dispatch($event, $action);
if ($event->isPropagationStopped()) {
throw new AbortColumnCreateException('Column cannot be created now');
}
}
/**
* @throws AbortColumnUpdateException
* @throws NoListenerException
*/
public function dispatchPreUpdateColumnEvent(LeadField $leadField): void
{
$action = LeadEvents::LEAD_FIELD_PRE_UPDATE_COLUMN_BACKGROUND_JOB;
if (!$this->dispatcher->hasListeners($action)) {
throw new NoListenerException('There is no Listener for this event');
}
$event = new UpdateColumnBackgroundEvent($leadField);
$this->dispatcher->dispatch($event, $action);
if ($event->isPropagationStopped()) {
throw new AbortColumnUpdateException('Column cannot be updated now');
}
}
}
|