13
13
14
14
use Symfony \UX \TwigComponent \BlockStack ;
15
15
use Twig \Compiler ;
16
+ use Twig \Extension \CoreExtension ;
16
17
use Twig \Node \Expression \AbstractExpression ;
17
18
use Twig \Node \Node ;
18
19
@@ -43,6 +44,17 @@ public function compile(Compiler $compiler): void
43
44
{
44
45
$ compiler ->addDebugInfo ($ this );
45
46
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
+
46
58
/*
47
59
* Block 1) PreCreateForRender handling
48
60
*
@@ -55,7 +67,7 @@ public function compile(Compiler $compiler): void
55
67
->raw (']->extensionPreCreateForRender( ' )
56
68
->string ($ this ->getAttribute ('component ' ))
57
69
->raw (', ' )
58
- ->raw ('twig_to_array ( ' )
70
+ ->raw ('$toArray ( ' )
59
71
;
60
72
$ this ->writeProps ($ compiler )
61
73
->raw (') ' )
@@ -86,7 +98,7 @@ public function compile(Compiler $compiler): void
86
98
->string (ComponentExtension::class)
87
99
->raw (']->startEmbeddedComponentRender( ' )
88
100
->string ($ this ->getAttribute ('component ' ))
89
- ->raw (', twig_to_array ( ' )
101
+ ->raw (', $toArray ( ' )
90
102
;
91
103
$ this ->writeProps ($ compiler )
92
104
->raw ('), ' )
0 commit comments