<?php
declare(strict_types=1);
namespace App\Event;
use App\Event\LastViewedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use App\Services\LastViewedService;
class LastViewedSubscriber implements EventSubscriberInterface
{
protected LastViewedService $lastViewedService;
public function __construct(LastViewedService $lastViewedService)
{
$this->lastViewedService = $lastViewedService;
}
public static function getSubscribedEvents()
{
return [
LastViewedEvent::NAME => 'onLastViewed',
];
}
public function onLastViewed(LastViewedEvent $event): void
{
$this->lastViewedService->saveLastViewedItem(
$event->getSalesRep(),
$event->getEntityType(),
$event->getEntityId()
);
}
}