Skip to content

Commit 7b60229

Browse files
authored
Merge branch 'symfony:2.x' into live-component-force-post-requests
2 parents 86a09a6 + d109f66 commit 7b60229

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/TwigComponent/src/Twig/ComponentNode.php

Lines changed: 14 additions & 2 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

@@ -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('), ')

src/TwigComponent/src/Twig/PropsTokenParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function parse(Token $token): Node
3030
$names = [];
3131
$values = [];
3232
while (!$stream->nextIf(Token::BLOCK_END_TYPE)) {
33-
$name = $stream->expect(\Twig\Token::NAME_TYPE)->getValue();
33+
$name = $stream->expect(Token::NAME_TYPE)->getValue();
3434

3535
if ($stream->nextIf(Token::OPERATOR_TYPE, '=')) {
3636
$values[$name] = $parser->getExpressionParser()->parseExpression();
@@ -39,7 +39,7 @@ public function parse(Token $token): Node
3939
$names[] = $name;
4040

4141
if (!$stream->nextIf(Token::PUNCTUATION_TYPE)) {
42-
$stream->expect(\Twig\Token::BLOCK_END_TYPE);
42+
$stream->expect(Token::BLOCK_END_TYPE);
4343
break;
4444
}
4545
}

0 commit comments

Comments
 (0)