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

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.     public function __construct(Environment $twig)
  13.     {
  14.         $this->twig $twig;
  15.     }
  16.     /**
  17.      * @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
  18.      */
  19.     public static function getSubscribedEvents()
  20.     {
  21.         return [KernelEvents::REQUEST => 'onKernelRequest'];
  22.     }
  23.     public function onKernelRequest(RequestEvent $event): void
  24.     {
  25.         $timezone = (string) $event->getRequest()->cookies->get(self::TIMEZONE_COOKIE);
  26.         if (!$timezone || !\in_array($timezonetimezone_identifiers_list(), true)) {
  27.             $timezone 'UTC';
  28.         }
  29.         if (!$this->twig->hasExtension(CoreExtension::class)) {
  30.             return;
  31.         }
  32.         /** @var CoreExtension $coreExtension */
  33.         $coreExtension $this->twig->getExtension(CoreExtension::class);
  34.         $coreExtension->setTimezone($timezone);
  35.     }
  36. }