src/Service/SuperAdmin/EventListener/UserActivityListener.php line 38

Open in your IDE?
  1. <?php
  2. namespace Harmonizely\Service\SuperAdmin\EventListener;
  3. use Harmonizely\Core\Security\Contract\ISuperAdminSecurityHelper ;
  4. use Harmonizely\Entity\SuperAdmin\UserEntity;
  5. use Harmonizely\Repository\SuperAdmin\Contract\IUserRepository;
  6. use Symfony\Component\HttpKernel\Event\RequestEvent;
  7. class UserActivityListener
  8. {
  9.     /**
  10.      * @var ISuperAdminSecurityHelper
  11.      */
  12.     private ISuperAdminSecurityHelper $security;
  13.     /**
  14.      * @var IUserRepository
  15.      */
  16.     private IUserRepository $repository;
  17.     /**
  18.      * UserActivityListener constructor.
  19.      *
  20.      * @param ISuperAdminSecurityHelper $security
  21.      * @param IUserRepository $repository
  22.      */
  23.     public function __construct(ISuperAdminSecurityHelper $securityIUserRepository $repository)
  24.     {
  25.         $this->security $security;
  26.         $this->repository $repository;
  27.     }
  28.     /**
  29.      * @param RequestEvent $event
  30.      */
  31.     public function onRequest(RequestEvent $event): void
  32.     {
  33.         $user $this->security->getUser();
  34.         if ($user instanceof UserEntity) {
  35.             if ($user->updateLastAccessTime()) {
  36.                 $this->repository->save($user);
  37.             }
  38.         }
  39.     }
  40. }