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

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