From b94414b3b9e0c523677c0bf31e8975231b55f18a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 7 Sep 2024 15:25:07 +0200 Subject: [PATCH] [TwigBundle] Add support for resetting globals between HTTP requests --- DependencyInjection/TwigExtension.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/DependencyInjection/TwigExtension.php b/DependencyInjection/TwigExtension.php index 4cec7806..18373aca 100644 --- a/DependencyInjection/TwigExtension.php +++ b/DependencyInjection/TwigExtension.php @@ -24,6 +24,7 @@ use Symfony\Component\Mailer\Mailer; use Symfony\Component\Translation\Translator; use Symfony\Contracts\Service\ResetInterface; +use Twig\Environment; use Twig\Extension\ExtensionInterface; use Twig\Extension\RuntimeExtensionInterface; use Twig\Loader\LoaderInterface; @@ -45,6 +46,10 @@ public function load(array $configs, ContainerBuilder $container) $loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('twig.php'); + if (method_exists(Environment::class, 'resetGlobals')) { + $container->getDefinition('twig')->addTag('kernel.reset', ['method' => 'resetGlobals']); + } + if ($container::willBeAvailable('symfony/form', Form::class, ['symfony/twig-bundle'], true)) { $loader->load('form.php');