vendor/stimactiv/core-bundle/src/EventSubscriber/ActivitySubscriber.php line 23

Open in your IDE?
  1. <?php
  2. namespace Stimactiv\CoreBundle\EventSubscriber;
  3. use Stimactiv\CoreBundle\Entity\BaseUser;
  4. use Stimactiv\CoreBundle\Model\BaseUserManager;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\KernelEvents;
  7. use Symfony\Component\Security\Core\Security;
  8. class ActivitySubscriber implements EventSubscriberInterface
  9. {
  10.     private BaseUserManager $userManager;
  11.     private Security $security;
  12.     public function __construct(BaseUserManager $userManagerSecurity $security)
  13.     {
  14.         $this->userManager $userManager;
  15.         $this->security $security;
  16.     }
  17.     public function onTerminate(): void
  18.     {
  19.         $user $this->security->getUser();
  20.         if ($user instanceof BaseUser && !$user->isActiveNow()) {
  21.             $user->setLastActivityAt(new \DateTime());
  22.             $this->userManager->update($user);
  23.         }
  24.     }
  25.     public static function getSubscribedEvents(): array
  26.     {
  27.         return [
  28.             // must be registered before (i.e. with a higher priority than) the default Locale listener
  29.             KernelEvents::TERMINATE => [['onTerminate'20]],
  30.         ];
  31.     }
  32. }