1313
1414use Symfony \UX \TwigComponent \BlockStack ;
1515use Twig \Compiler ;
16+ use Twig \Extension \CoreExtension ;
1617use Twig \Node \Expression \AbstractExpression ;
1718use Twig \Node \Node ;
1819
@@ -43,6 +44,17 @@ public function compile(Compiler $compiler): void
4344 {
4445 $ compiler ->addDebugInfo ($ this );
4546
47+ // since twig/twig 3.9.0: Using the internal "twig_to_array" function is deprecated.
48+ $ compiler
49+ ->write ('$toArray = function ($data) { ' )
50+ ;
51+
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+
4658 /*
4759 * Block 1) PreCreateForRender handling
4860 *
@@ -55,7 +67,7 @@ public function compile(Compiler $compiler): void
5567 ->raw (']->extensionPreCreateForRender( ' )
5668 ->string ($ this ->getAttribute ('component ' ))
5769 ->raw (', ' )
58- ->raw ('twig_to_array ( ' )
70+ ->raw ('$toArray ( ' )
5971 ;
6072 $ this ->writeProps ($ compiler )
6173 ->raw (') ' )
@@ -86,7 +98,7 @@ public function compile(Compiler $compiler): void
8698 ->string (ComponentExtension::class)
8799 ->raw (']->startEmbeddedComponentRender( ' )
88100 ->string ($ this ->getAttribute ('component ' ))
89- ->raw (', twig_to_array ( ' )
101+ ->raw (', $toArray ( ' )
90102 ;
91103 $ this ->writeProps ($ compiler )
92104 ->raw ('), ' )
0 commit comments