vendor/shopware/storefront/Framework/Twig/TwigAppVariable.php line 15

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Storefront\Framework\Twig;
  3. use Shopware\Core\Framework\Log\Package;
  4. use Symfony\Bridge\Twig\AppVariable;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\RequestStack;
  7. use Symfony\Component\HttpFoundation\Session\Session;
  8. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  9. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. #[Package('core')]
  12. class TwigAppVariable extends AppVariable
  13. {
  14.     private ?Request $request null;
  15.     private AppVariable $appVariable;
  16.     private array $allowList;
  17.     /**
  18.      * @internal
  19.      */
  20.     public function __construct(AppVariable $appVariable, array $allowList = [])
  21.     {
  22.         $this->allowList $allowList;
  23.         $this->appVariable $appVariable;
  24.     }
  25.     /**
  26.      * @return Request|null
  27.      */
  28.     public function getRequest()
  29.     {
  30.         if ($this->request !== null) {
  31.             return $this->request;
  32.         }
  33.         $request $this->appVariable->getRequest();
  34.         if ($request === null) {
  35.             throw new \RuntimeException('The "app.request" variable is not available.');
  36.         }
  37.         $clonedRequest = clone $request;
  38.         $clonedRequest->server = clone $clonedRequest->server;
  39.         foreach ($clonedRequest->server->all() as $key => $_) {
  40.             if (!\in_array(strtolower($key), $this->allowListtrue)) {
  41.                 $clonedRequest->server->remove($key);
  42.             }
  43.         }
  44.         $this->request $clonedRequest;
  45.         return $clonedRequest;
  46.     }
  47.     public function setTokenStorage(TokenStorageInterface $tokenStorage): void
  48.     {
  49.         $this->appVariable->setTokenStorage($tokenStorage);
  50.     }
  51.     public function setRequestStack(RequestStack $requestStack): void
  52.     {
  53.         $this->appVariable->setRequestStack($requestStack);
  54.     }
  55.     public function setEnvironment(string $environment): void
  56.     {
  57.         $this->appVariable->setEnvironment($environment);
  58.     }
  59.     public function setDebug(bool $debug): void
  60.     {
  61.         $this->appVariable->setDebug($debug);
  62.     }
  63.     /**
  64.      * @return TokenInterface|null
  65.      */
  66.     public function getToken()
  67.     {
  68.         return $this->appVariable->getToken();
  69.     }
  70.     /**
  71.      * @return UserInterface|null
  72.      */
  73.     public function getUser()
  74.     {
  75.         return $this->appVariable->getUser();
  76.     }
  77.     /**
  78.      * @return Session|null
  79.      */
  80.     public function getSession()
  81.     {
  82.         return $this->appVariable->getSession();
  83.     }
  84.     /**
  85.      * @return string
  86.      */
  87.     public function getEnvironment()
  88.     {
  89.         return $this->appVariable->getEnvironment();
  90.     }
  91.     /**
  92.      * @return bool
  93.      */
  94.     public function getDebug()
  95.     {
  96.         return $this->appVariable->getDebug();
  97.     }
  98.     /**
  99.      * @return array
  100.      */
  101.     public function getFlashes($types null)
  102.     {
  103.         return $this->appVariable->getFlashes($types);
  104.     }
  105. }