Skip to content

Commit 2a6ec45

Browse files
committed
[TwigComponent] Optimize twig_to_array BC layer
Remove anonymous method as the result is known during compilation
1 parent 3c5d7a4 commit 2a6ec45

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/TwigComponent/src/Twig/ComponentNode.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,10 @@ public function compile(Compiler $compiler): void
4545
$compiler->addDebugInfo($this);
4646

4747
// since twig/twig 3.9.0: Using the internal "twig_to_array" function is deprecated.
48-
$compiler
49-
->write('$toArray = function ($data) {')
50-
;
51-
5248
if (method_exists(CoreExtension::class, 'toArray')) {
53-
$compiler->write('return Twig\Extension\CoreExtension::toArray($data);};');
49+
$twig_to_array = 'Twig\Extension\CoreExtension::toArray';
5450
} else {
55-
$compiler->write('return twig_to_array($data);};');
51+
$twig_to_array = 'twig_to_array';
5652
}
5753

5854
/*
@@ -67,7 +63,8 @@ public function compile(Compiler $compiler): void
6763
->raw(']->extensionPreCreateForRender(')
6864
->string($this->getAttribute('component'))
6965
->raw(', ')
70-
->raw('$toArray(')
66+
->raw($twig_to_array)
67+
->raw('(')
7168
;
7269
$this->writeProps($compiler)
7370
->raw(')')
@@ -98,7 +95,9 @@ public function compile(Compiler $compiler): void
9895
->string(ComponentExtension::class)
9996
->raw(']->startEmbeddedComponentRender(')
10097
->string($this->getAttribute('component'))
101-
->raw(', $toArray(')
98+
->raw(', ')
99+
->raw($twig_to_array)
100+
->raw('(')
102101
;
103102
$this->writeProps($compiler)
104103
->raw('), ')

0 commit comments

Comments
 (0)