<?php
namespace DW\GingerBundle\EventSubscriber;
use DW\GingerBundle\DWGingerEvents;
use DW\GingerBundle\Event\CRUDEvent;
use DW\GingerBundle\Event\TopicIntegrationEvent;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
readonly class TopicAttributeEventsLogger implements EventSubscriberInterface
{
public function __construct(
private LoggerInterface $gingerCoreEventsLogger,
) {}
public function onTopicAttributeUpdate(CRUDEvent $event): void
{
$this->gingerCoreEventsLogger->info('TopicAttribute has been updated');
$this->gingerCoreEventsLogger->debug(
'Todo: Maybe update the title of a related newsletter list?',
[
'updated_attribute_title' => $event->getObject()->getTitle()
]
);
}
public function onTopicAttributeDelete(CRUDEvent $event): void
{
$this->gingerCoreEventsLogger->info('TopicAttribute has been deleted');
$this->gingerCoreEventsLogger->debug(
'Todo: Maybe delete a related newsletter list?',
[
'some-attribute_props' => [
'id' => $event->getObject()->getId(),
'title' => $event->getObject()->getTitle(),
'type' => $event->getObject()->getType(),
]
]
);
}
public function onTopicAttributeIntegrationAdd(TopicIntegrationEvent $event): void
{
$this->gingerCoreEventsLogger->info('Integration has been ADDED to a Topic Attribute');
$this->gingerCoreEventsLogger->debug(
'Todo: Maybe subscribe related people to a linked newsletter list?',
[
'topic' => [
'id' => $event->getTopic()->getId(),
'title' => $event->getTopic()->getTitle(),
],
'integration' => [
'id' => $event->getIntegration()->getId(),
'title' => $event->getIntegration()->getTitle(),
]
]
);
}
public function onTopicAttributeIntegrationRemove(TopicIntegrationEvent $event): void
{
$this->gingerCoreEventsLogger->info('Integration has been REMOVED from a Topic Attribute');
$this->gingerCoreEventsLogger->debug(
'Todo: Maybe un-subscribe related people from a linked newsletter list?',
[
'topic' => [
'id' => $event->getTopic()->getId(),
'title' => $event->getTopic()->getTitle(),
],
'integration' => [
'id' => $event->getIntegration()->getId(),
'title' => $event->getIntegration()->getTitle(),
]
]
);
}
public static function getSubscribedEvents(): array
{
return [
DWGingerEvents::TOPIC_ATTRIBUTE['ON_TOPIC_ATTRIBUTE_UPDATE'] => 'onTopicAttributeUpdate',
DWGingerEvents::TOPIC_ATTRIBUTE['ON_TOPIC_ATTRIBUTE_INTEGRATION_ADD'] => 'onTopicAttributeIntegrationAdd',
DWGingerEvents::TOPIC_ATTRIBUTE['ON_TOPIC_ATTRIBUTE_INTEGRATION_REMOVE'] => 'onTopicAttributeIntegrationRemove',
DWGingerEvents::TOPIC_ATTRIBUTE['ON_TOPIC_ATTRIBUTE_DELETE'] => 'onTopicAttributeDelete',
];
}
}