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

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