src/EventSubscriber/TimezoneSubscriber.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Service\TimezoneService;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpKernel\KernelEvents;
  6. use Symfony\Component\Security\Core\Authentication\Token\Storage\UsageTrackingTokenStorage;
  7. class TimezoneSubscriber implements EventSubscriberInterface
  8. {
  9.     /**
  10.      * TimezoneSubscriber constructor.
  11.      */
  12.     public function __construct(
  13.         protected UsageTrackingTokenStorage $tokenStorage,
  14.         protected TimezoneService $timezoneService
  15.     ) {
  16.     }
  17.     /**
  18.      * @throws \Exception
  19.      */
  20.     public function onKernelRequest(): void
  21.     {
  22.         $this->timezoneService->set($this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null);
  23.     }
  24.     public static function getSubscribedEvents(): array
  25.     {
  26.         return [
  27.             KernelEvents::REQUEST => [['onKernelRequest'1]],
  28.         ];
  29.     }
  30. }