<?php
namespace App\EventSubscriber;
use App\Service\TimezoneService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Security\Core\Authentication\Token\Storage\UsageTrackingTokenStorage;
class TimezoneSubscriber implements EventSubscriberInterface
{
/**
* TimezoneSubscriber constructor.
*/
public function __construct(
protected UsageTrackingTokenStorage $tokenStorage,
protected TimezoneService $timezoneService
) {
}
/**
* @throws \Exception
*/
public function onKernelRequest(): void
{
$this->timezoneService->set($this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null);
}
public static function getSubscribedEvents(): array
{
return [
KernelEvents::REQUEST => [['onKernelRequest', 1]],
];
}
}