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

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 Twig\Extension\CoreExtension;
  6. class TwigDateRequestListener implements EventSubscriberInterface
  7. {
  8.     public const TIMEZONE_COOKIE 'timezone';
  9.     /**
  10.      * @var \Twig_Environment
  11.      */
  12.     private $twig;
  13.     public function __construct(\Twig_Environment $twig)
  14.     {
  15.         $this->twig $twig;
  16.     }
  17.     public static function getSubscribedEvents()
  18.     {
  19.         return ['kernel.request' => 'onKernelRequest'];
  20.     }
  21.     public function onKernelRequest(RequestEvent $event): void
  22.     {
  23.         $timezone $event->getRequest()->cookies->get(self::TIMEZONE_COOKIE);
  24.         if (!$timezone || !\in_array($timezonetimezone_identifiers_list(), true)) {
  25.             $timezone 'UTC';
  26.         }
  27.         if (!$this->twig->hasExtension(CoreExtension::class)) {
  28.             return;
  29.         }
  30.         /** @var CoreExtension $coreExtension */
  31.         $coreExtension $this->twig->getExtension(CoreExtension::class);
  32.         $coreExtension->setTimezone($timezone);
  33.     }
  34. }