src/Event/LastViewedSubscriber.php line 27

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Event;
  4. use App\Event\LastViewedEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use App\Services\LastViewedService;
  7. class LastViewedSubscriber implements EventSubscriberInterface
  8. {
  9.     protected LastViewedService $lastViewedService;
  10.     public function __construct(LastViewedService $lastViewedService)
  11.     {
  12.         $this->lastViewedService $lastViewedService;
  13.     }
  14.     public static function getSubscribedEvents()
  15.     {
  16.         return [
  17.             LastViewedEvent::NAME => 'onLastViewed',
  18.         ];
  19.     }
  20.     public function onLastViewed(LastViewedEvent $event): void
  21.     {
  22.         $this->lastViewedService->saveLastViewedItem(
  23.             $event->getSalesRep(),
  24.             $event->getEntityType(),
  25.             $event->getEntityId()
  26.         );
  27.     }
  28. }