Skip to content

Commit

Permalink
Inject Twig Environment service
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitro-N committed Oct 10, 2024
1 parent 49015e5 commit b7ad1a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 8 additions & 4 deletions Security/AccessHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -46,7 +48,7 @@ class AccessHandler
private $tokenStorage;

/**
* @var \Twig_Environment
* @var Environment
*/
private $twigEnvironment;

Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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,
]);
Expand Down

0 comments on commit b7ad1a8

Please sign in to comment.