Skip to content

Commit 0b4dd3a

Browse files
feat: Make sure to not add Twig extensions multiple times
1 parent fe0f648 commit 0b4dd3a

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/Template/Twig.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,17 @@ public function render(): string
5050
*/
5151
public static function addExtension(\Twig\Extension\ExtensionInterface $extension): void
5252
{
53-
self::twig()->addExtension($extension);
53+
$twig = self::twig();
54+
55+
if ($extension instanceof \Twig\Extension\AttributeExtension) {
56+
$extension_class = $extension->getClass();
57+
} else {
58+
$extension_class = $extension::class;
59+
}
60+
61+
if (!$twig->hasExtension($extension_class)) {
62+
self::twig()->addExtension($extension);
63+
}
5464
}
5565

5666
/**

src/Tests/ApplicationHelper.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ trait ApplicationHelper
5151
#[\PHPUnit\Framework\Attributes\BeforeClass]
5252
public static function loadApplication(): void
5353
{
54-
// This avoids to register extensions multiple times (normally done in
55-
// the Application class constructor) as it would fail.
56-
\Minz\Template\Twig::reset();
57-
5854
$app_name = \Minz\Configuration::$app_name;
5955
$application_class_name = "\\{$app_name}\\Application";
6056
try {

0 commit comments

Comments
 (0)