|
25 | 25 | use Twig\Token; |
26 | 26 | use Twig\TokenParser\AbstractTokenParser; |
27 | 27 |
|
| 28 | +use function method_exists; |
| 29 | + |
28 | 30 | class TransTokenParser extends AbstractTokenParser |
29 | 31 | { |
30 | 32 | /** |
@@ -60,18 +62,24 @@ protected function preParse(Token $token): array |
60 | 62 | /* If we aren't closing the block, do we have a domain? */ |
61 | 63 | if ($stream->test(Token::NAME_TYPE)) { |
62 | 64 | $stream->expect(Token::NAME_TYPE, 'from'); |
63 | | - $domain = $this->parser->getExpressionParser()->parseExpression(); |
| 65 | + $domain = method_exists($this->parser, 'parseExpression') |
| 66 | + ? $this->parser->parseExpression() |
| 67 | + : $this->parser->getExpressionParser()->parseExpression(); |
64 | 68 | } |
65 | 69 |
|
66 | 70 | if (! $stream->test(Token::BLOCK_END_TYPE)) { |
67 | | - $body = $this->parser->getExpressionParser()->parseExpression(); |
| 71 | + $body = method_exists($this->parser, 'parseExpression') |
| 72 | + ? $this->parser->parseExpression() |
| 73 | + : $this->parser->getExpressionParser()->parseExpression(); |
68 | 74 | } else { |
69 | 75 | $stream->expect(Token::BLOCK_END_TYPE); |
70 | 76 | $body = $this->parser->subparse([$this, 'decideForFork']); |
71 | 77 | $next = $stream->next()->getValue(); |
72 | 78 |
|
73 | 79 | if ($next === 'plural') { |
74 | | - $count = $this->parser->getExpressionParser()->parseExpression(); |
| 80 | + $count = method_exists($this->parser, 'parseExpression') |
| 81 | + ? $this->parser->parseExpression() |
| 82 | + : $this->parser->getExpressionParser()->parseExpression(); |
75 | 83 | $stream->expect(Token::BLOCK_END_TYPE); |
76 | 84 | $plural = $this->parser->subparse([$this, 'decideForFork']); |
77 | 85 | $next = $stream->next()->getValue(); |
|
0 commit comments