Skip to content

Commit 16f0c79

Browse files
committed
test on compile time
1 parent 6b5e43d commit 16f0c79

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/TwigComponent/src/Twig/ComponentNode.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\UX\TwigComponent\BlockStack;
1515
use Twig\Compiler;
16+
use Twig\Extension\CoreExtension;
1617
use Twig\Node\Expression\AbstractExpression;
1718
use Twig\Node\Node;
1819

@@ -46,13 +47,14 @@ public function compile(Compiler $compiler): void
4647
// since twig/twig 3.9.0: Using the internal "twig_to_array" function is deprecated.
4748
$compiler
4849
->write('$toArray = function ($data) {')
49-
->write('if (method_exists(Twig\Extension\CoreExtension::class, \'toArray\')) {')
50-
->write('return Twig\Extension\CoreExtension::toArray($data);')
51-
->write('}')
52-
->write('return twig_to_array($data);')
53-
->write('};')
5450
;
5551

52+
if (method_exists(CoreExtension::class, 'toArray')) {
53+
$compiler->write('return Twig\Extension\CoreExtension::toArray($data);};');
54+
} else {
55+
$compiler->write('return twig_to_array($data);};');
56+
}
57+
5658
/*
5759
* Block 1) PreCreateForRender handling
5860
*

0 commit comments

Comments
 (0)