From b7ad1a8d4f4dbaaed02ab328f2d5efedccdaca3d Mon Sep 17 00:00:00 2001 From: Sergey Zvyagintsev Date: Thu, 10 Oct 2024 16:00:17 +0700 Subject: [PATCH] Inject Twig Environment service --- Resources/config/services.yml | 2 +- Security/AccessHandler.php | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Resources/config/services.yml b/Resources/config/services.yml index bdd7572..6c05c3e 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -1,7 +1,7 @@ services: glavweb_security.access_handler: class: Glavweb\SecurityBundle\Security\AccessHandler - arguments: ["@annotation_reader", "@security.token_storage"] + arguments: ["@annotation_reader", "@security.token_storage", "@?twig"] glavweb_security.access_query_builder_filter: class: Glavweb\SecurityBundle\Security\QueryBuilderFilter diff --git a/Security/AccessHandler.php b/Security/AccessHandler.php index 08ab1ea..ab1f072 100644 --- a/Security/AccessHandler.php +++ b/Security/AccessHandler.php @@ -16,6 +16,8 @@ use Glavweb\SecurityBundle\Mapping\Annotation\Access; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\User\UserInterface; +use Twig\Environment; +use Twig\Loader\ArrayLoader; /** * Class AccessHandler @@ -46,7 +48,7 @@ class AccessHandler private $tokenStorage; /** - * @var \Twig_Environment + * @var Environment */ private $twigEnvironment; @@ -55,11 +57,13 @@ class AccessHandler * * @param Reader $annotationReader * @param TokenStorageInterface $tokenStorage + * @param Environment $twigEnvironment */ - public function __construct(Reader $annotationReader, TokenStorageInterface $tokenStorage) + public function __construct(Reader $annotationReader, TokenStorageInterface $tokenStorage, Environment $twigEnvironment = null) { $this->annotationReader = $annotationReader; $this->tokenStorage = $tokenStorage; + $this->twigEnvironment = $twigEnvironment; } /** @@ -240,12 +244,12 @@ public function conditionPlaceholder($condition, $alias, UserInterface $user = n } /** - * @return \Twig_Environment + * @return Environment */ private function getTwigEnvironment() { if (!$this->twigEnvironment) { - $this->twigEnvironment = new \Twig_Environment(new \Twig_Loader_Array([]), [ + $this->twigEnvironment = new Environment(new ArrayLoader(), [ 'strict_variables' => true, 'autoescape' => false, ]);