<?php
namespace App\Subscriber\Scheduler;
use Cms\CoreBundle\Util\Doctrine\EntityManager;
use Platform\QueueBundle\Event\AsyncEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
*
*/
abstract class AbstractSchedulerSubscriber implements EventSubscriberInterface
{
/**
* All extending classes need to set this value to something unique.
* It is the name of the event to watch for that is going to be injected into the MQ by the Lambda functions.
*/
public const EVENT = null;
/**
* @var EntityManager
*/
protected EntityManager $em;
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents(): array
{
return static::EVENT ? [
static::EVENT => ['onEvent', 0],
] : [];
}
/**
* @param EntityManager $em
*/
public function __construct(EntityManager $em)
{
$this->em = $em;
}
/**
* @param AsyncEvent $event
* @return void
*/
public function onEvent(AsyncEvent $event): void
{
if ( ! static::EVENT) {
return;
}
try {
$this->handleEvent($event);
} catch (\Exception $e) {
// TODO: an error happened, need to log it somewhere eventually...
}
}
/**
* @param AsyncEvent $event
* @return void
*/
abstract protected function handleEvent(AsyncEvent $event): void;
}