vendor/shopware/storefront/Framework/Twig/TwigDateRequestListener.php line 33

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Storefront\Framework\Twig;
  3. use Composer\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpKernel\Event\RequestEvent;
  5. use Symfony\Component\HttpKernel\KernelEvents;
  6. use Twig\Environment;
  7. use Twig\Extension\CoreExtension;
  8. class TwigDateRequestListener implements EventSubscriberInterface
  9. {
  10.     public const TIMEZONE_COOKIE 'timezone';
  11.     private Environment $twig;
  12.     /**
  13.      * @internal
  14.      */
  15.     public function __construct(Environment $twig)
  16.     {
  17.         $this->twig $twig;
  18.     }
  19.     /**
  20.      * @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
  21.      */
  22.     public static function getSubscribedEvents()
  23.     {
  24.         return [KernelEvents::REQUEST => 'onKernelRequest'];
  25.     }
  26.     public function onKernelRequest(RequestEvent $event): void
  27.     {
  28.         $timezone = (string) $event->getRequest()->cookies->get(self::TIMEZONE_COOKIE);
  29.         if (!$timezone || !\in_array($timezonetimezone_identifiers_list(), true)) {
  30.             $timezone 'UTC';
  31.         }
  32.         if (!$this->twig->hasExtension(CoreExtension::class)) {
  33.             return;
  34.         }
  35.         /** @var CoreExtension $coreExtension */
  36.         $coreExtension $this->twig->getExtension(CoreExtension::class);
  37.         $coreExtension->setTimezone($timezone);
  38.     }
  39. }