Skip to content

Commit a282ed5

Browse files
committed
minor #2591 [TwigComponent] Fix Twig 3.21 deprecations (getExpressionParser) (smnandre)
This PR was merged into the 2.x branch. Discussion ---------- [TwigComponent] Fix Twig 3.21 deprecations (getExpressionParser) | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT Following twigphp/Twig#4543 Commits ------- dfeb323 [TwigComponent] Fix getExpressionParser deprecations (Twig 3.21)
2 parents 9cf1a01 + dfeb323 commit a282ed5

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/TwigComponent/src/Twig/ComponentTokenParser.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ final class ComponentTokenParser extends AbstractTokenParser
3333
public function parse(Token $token): Node
3434
{
3535
$stream = $this->parser->getStream();
36-
$componentName = $this->componentName($this->parser->getExpressionParser()->parseExpression());
36+
if (method_exists($this->parser, 'parseExpression')) {
37+
// Since Twig 3.21
38+
$componentName = $this->componentName($this->parser->parseExpression());
39+
} else {
40+
$componentName = $this->componentName($this->parser->getExpressionParser()->parseExpression());
41+
}
3742

3843
[$propsExpression, $only] = $this->parseArguments();
3944

@@ -98,7 +103,12 @@ private function parseArguments(): array
98103
$variables = null;
99104

100105
if ($stream->nextIf(Token::NAME_TYPE, 'with')) {
101-
$variables = $this->parser->getExpressionParser()->parseExpression();
106+
if (method_exists($this->parser, 'parseExpression')) {
107+
// Since Twig 3.21
108+
$variables = $this->parser->parseExpression();
109+
} else {
110+
$variables = $this->parser->getExpressionParser()->parseExpression();
111+
}
102112
}
103113

104114
$only = false;

src/TwigComponent/src/Twig/PropsTokenParser.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ public function parse(Token $token): Node
3333
$name = $stream->expect(Token::NAME_TYPE)->getValue();
3434

3535
if ($stream->nextIf(Token::OPERATOR_TYPE, '=')) {
36-
$values[$name] = $parser->getExpressionParser()->parseExpression();
36+
if (method_exists($parser, 'parseExpression')) {
37+
// Since Twig 3.21
38+
$values[$name] = $parser->parseExpression();
39+
} else {
40+
$values[$name] = $parser->getExpressionParser()->parseExpression();
41+
}
3742
}
3843

3944
$names[] = $name;

0 commit comments

Comments
 (0)