src/EventListener/UserLastActivity.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Entity\User;
  4. use App\Repository\UserRepository;
  5. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  6. class UserLastActivity
  7. {
  8.     /** @var TokenStorageInterface */
  9.     private $tokenStorage;
  10.     /** @var UserRepository */
  11.     private $userRepository;
  12.     public function __construct(
  13.         TokenStorageInterface $tokenStorage,
  14.         UserRepository $userRepository)
  15.     {
  16.         $this->tokenStorage $tokenStorage;
  17.         $this->userRepository $userRepository;
  18.     }
  19.     public function onKernelRequest(): void
  20.     {
  21.         if (null !== $this->tokenStorage->getToken() && ($user $this->tokenStorage->getToken()->getUser()) instanceof User) {
  22.             /* @var User $user */
  23.             $this->userRepository->updateLastActivity($user);
  24.         }
  25.     }
  26. }