8000 Add BC layer for `twig_to_array` deprecation then removal · symfony/ux@eb6a893 · GitHub
[go: up one dir, main page]

Skip to content

Commit eb6a893

Browse files
smnandrefabpot
authored andcommitted
Add BC layer for twig_to_array deprecation then removal
1 parent 42b4665 commit eb6a893

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/TwigComponent/src/Twig/ComponentNode.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\UX\TwigComponent\Twig;
1313

1414
use Twig\Compiler;
15+
use Twig\Extension\CoreExtension;
1516
use Twig\Node\EmbedNode;
1617
use Twig\Node\Expression\AbstractExpression;
1718

@@ -34,13 +35,21 @@ public function compile(Compiler $compiler): void
3435
{
3536
$compiler->addDebugInfo($this);
3637

38+
// since twig/twig 3.9.0: Using the internal "twig_to_array" function is deprecated.
39+
if (method_exists(CoreExtension::class, 'toArray')) {
40+
$twig_to_array = 'Twig\Extension\CoreExtension::toArray';
41+
} else {
42+
$twig_to_array = 'twig_to_array';
43+
}
44+
3745
$compiler
3846
->raw('$props = $this->extensions[')
3947
->string(ComponentExtension::class)
4048
->raw(']->embeddedContext(')
4149
->string($this->getAttribute('component'))
4250
->raw(', ')
43-
->raw('twig_to_array(')
51+
->raw($twig_to_array)
52+
->raw('(')
4453
->subcompile($this->getNode('variables'))
4554
->raw('), ')
4655
->raw($this->getAttribute('only') ? '[]' : '$context')

0 commit comments

Comments
 (0)
0