<?php
namespace App\EventSubscriber;
use App\Event\ActivityLogDataEvent;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use App\Utils\ActivityLogHandler;
class ActivityLogDataSubscriber implements EventSubscriberInterface
{
private LoggerInterface $logger;
private $activityLogger;
public function __construct(LoggerInterface $logger, ActivityLogHandler $activityLogger )
{
$this->logger = $logger;
$this->activityLogger = $activityLogger;
}
public function onActivityLogDataEvent(ActivityLogDataEvent $event): void
{
$data = $event->getData();
// Log or process the data
$this->logger->info('ActivityLog data event handled', $data);
// Modify the data if needed
$this->activityLogger->activityLogSaveData($data['activityAction'],$data);
$data['processed'] = true;
$event->setData($data);
}
public static function getSubscribedEvents(): array
{
return [
'activity_log.data_event' => 'onActivityLogDataEvent',
];
}
}