Skip to content

Commit

Permalink
[TwigBundle] Add support for resetting globals between HTTP requests
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Sep 7, 2024
1 parent 997c002 commit b94414b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions DependencyInjection/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');

Expand Down

0 comments on commit b94414b

Please sign in to comment.