Skip to content

Commit

Permalink
Merge branch '6.4' into 7.2
Browse files Browse the repository at this point in the history
* 6.4:
  fix rendering notifier message options
  Enable `JSON_PRESERVE_ZERO_FRACTION` in `jsonRequest` method
  [TwigBridge] Fix compatibility with Twig 3.21
  • Loading branch information
xabbuh committed Feb 14, 2025
2 parents 60d6619 + d6aecb7 commit 45c00af
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
18 changes: 17 additions & 1 deletion TokenParser/DumpTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Symfony\Bridge\Twig\Node\DumpNode;
use Twig\Node\Expression\Variable\LocalVariable;
use Twig\Node\Node;
use Twig\Node\Nodes;
use Twig\Token;
use Twig\TokenParser\AbstractTokenParser;

Expand All @@ -34,13 +35,28 @@ public function parse(Token $token): Node
{
$values = null;
if (!$this->parser->getStream()->test(Token::BLOCK_END_TYPE)) {
$values = $this->parser->getExpressionParser()->parseMultitargetExpression();
$values = method_exists($this->parser, 'parseExpression') ?
$this->parseMultitargetExpression() :
$this->parser->getExpressionParser()->parseMultitargetExpression();
}
$this->parser->getStream()->expect(Token::BLOCK_END_TYPE);

return new DumpNode(class_exists(LocalVariable::class) ? new LocalVariable(null, $token->getLine()) : $this->parser->getVarName(), $values, $token->getLine(), $this->getTag());
}

private function parseMultitargetExpression(): Node
{
$targets = [];
while (true) {
$targets[] = $this->parser->parseExpression();
if (!$this->parser->getStream()->nextIf(Token::PUNCTUATION_TYPE, ',')) {
break;
}
}

return new Nodes($targets);
}

public function getTag(): string
{
return 'dump';
Expand Down
10 changes: 7 additions & 3 deletions TokenParser/FormThemeTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,24 @@ public function parse(Token $token): Node
$lineno = $token->getLine();
$stream = $this->parser->getStream();

$form = $this->parser->getExpressionParser()->parseExpression();
$parseExpression = method_exists($this->parser, 'parseExpression')
? $this->parser->parseExpression(...)
: $this->parser->getExpressionParser()->parseExpression(...);

$form = $parseExpression();
$only = false;

if ($this->parser->getStream()->test(Token::NAME_TYPE, 'with')) {
$this->parser->getStream()->next();
$resources = $this->parser->getExpressionParser()->parseExpression();
$resources = $parseExpression();

if ($this->parser->getStream()->nextIf(Token::NAME_TYPE, 'only')) {
$only = true;
}
} else {
$resources = new ArrayExpression([], $stream->getCurrent()->getLine());
do {
$resources->addElement($this->parser->getExpressionParser()->parseExpression());
$resources->addElement($parseExpression());
} while (!$stream->test(Token::BLOCK_END_TYPE));
}

Expand Down
4 changes: 3 additions & 1 deletion TokenParser/StopwatchTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public function parse(Token $token): Node
$stream = $this->parser->getStream();

// {% stopwatch 'bar' %}
$name = $this->parser->getExpressionParser()->parseExpression();
$name = method_exists($this->parser, 'parseExpression') ?
$this->parser->parseExpression() :
$this->parser->getExpressionParser()->parseExpression();

$stream->expect(Token::BLOCK_END_TYPE);

Expand Down
4 changes: 3 additions & 1 deletion TokenParser/TransDefaultDomainTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ final class TransDefaultDomainTokenParser extends AbstractTokenParser
{
public function parse(Token $token): Node
{
$expr = $this->parser->getExpressionParser()->parseExpression();
$expr = method_exists($this->parser, 'parseExpression') ?
$this->parser->parseExpression() :
$this->parser->getExpressionParser()->parseExpression();

$this->parser->getStream()->expect(Token::BLOCK_END_TYPE);

Expand Down
12 changes: 8 additions & 4 deletions TokenParser/TransTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,33 @@ public function parse(Token $token): Node
$vars = new ArrayExpression([], $lineno);
$domain = null;
$locale = null;
$parseExpression = method_exists($this->parser, 'parseExpression')
? $this->parser->parseExpression(...)
: $this->parser->getExpressionParser()->parseExpression(...);

if (!$stream->test(Token::BLOCK_END_TYPE)) {
if ($stream->test('count')) {
// {% trans count 5 %}
$stream->next();
$count = $this->parser->getExpressionParser()->parseExpression();
$count = $parseExpression();
}

if ($stream->test('with')) {
// {% trans with vars %}
$stream->next();
$vars = $this->parser->getExpressionParser()->parseExpression();
$vars = $parseExpression();
}

if ($stream->test('from')) {
// {% trans from "messages" %}
$stream->next();
$domain = $this->parser->getExpressionParser()->parseExpression();
$domain = $parseExpression();
}

if ($stream->test('into')) {
// {% trans into "fr" %}
$stream->next();
$locale = $this->parser->getExpressionParser()->parseExpression();
$locale = $parseExpression();
} elseif (!$stream->test(Token::BLOCK_END_TYPE)) {
throw new SyntaxError('Unexpected token. Twig was looking for the "with", "from", or "into" keyword.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
}
Expand Down

0 comments on commit 45c00af

Please sign in to comment.