Skip to content

Commit 0dfb1ec

Browse files
committed
Merge branch '7.2' into 7.3
* 7.2: fix rendering notifier message options Enable `JSON_PRESERVE_ZERO_FRACTION` in `jsonRequest` method [TwigBridge] Fix compatibility with Twig 3.21
2 parents 6a6ebac + 99d7695 commit 0dfb1ec

File tree

8 files changed

+42
-14
lines changed

8 files changed

+42
-14
lines changed

src/Symfony/Bridge/Twig/TokenParser/DumpTokenParser.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Bridge\Twig\Node\DumpNode;
1515
use Twig\Node\Expression\Variable\LocalVariable;
1616
use Twig\Node\Node;
17+
use Twig\Node\Nodes;
1718
use Twig\Token;
1819
use Twig\TokenParser\AbstractTokenParser;
1920

@@ -34,13 +35,28 @@ public function parse(Token $token): Node
3435
{
3536
$values = null;
3637
if (!$this->parser->getStream()->test(Token::BLOCK_END_TYPE)) {
37-
$values = $this->parser->getExpressionParser()->parseMultitargetExpression();
38+
$values = method_exists($this->parser, 'parseExpression') ?
39+
$this->parseMultitargetExpression() :
40+
$this->parser->getExpressionParser()->parseMultitargetExpression();
3841
}
3942
$this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
4043

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

47+
private function parseMultitargetExpression(): Node
48+
{
49+
$targets = [];
50+
while (true) {
51+
$targets[] = $this->parser->parseExpression();
52+
if (!$this->parser->getStream()->nextIf(Token::PUNCTUATION_TYPE, ',')) {
53+
break;
54+
}
55+
}
56+
57+
return new Nodes($targets);
58+
}
59+
4460
public function getTag(): string
4561
{
4662
return 'dump';

src/Symfony/Bridge/Twig/TokenParser/FormThemeTokenParser.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,24 @@ public function parse(Token $token): Node
2929
$lineno = $token->getLine();
3030
$stream = $this->parser->getStream();
3131

32-
$form = $this->parser->getExpressionParser()->parseExpression();
32+
$parseExpression = method_exists($this->parser, 'parseExpression')
33+
? $this->parser->parseExpression(...)
34+
: $this->parser->getExpressionParser()->parseExpression(...);
35+
36+
$form = $parseExpression();
3337
$only = false;
3438

3539
if ($this->parser->getStream()->test(Token::NAME_TYPE, 'with')) {
3640
$this->parser->getStream()->next();
37-
$resources = $this->parser->getExpressionParser()->parseExpression();
41+
$resources = $parseExpression();
3842

3943
if ($this->parser->getStream()->nextIf(Token::NAME_TYPE, 'only')) {
4044
$only = true;
4145
}
4246
} else {
4347
$resources = new ArrayExpression([], $stream->getCurrent()->getLine());
4448
do {
45-
$resources->addElement($this->parser->getExpressionParser()->parseExpression());
49+
$resources->addElement($parseExpression());
4650
} while (!$stream->test(Token::BLOCK_END_TYPE));
4751
}
4852

src/Symfony/Bridge/Twig/TokenParser/StopwatchTokenParser.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public function parse(Token $token): Node
3636
$stream = $this->parser->getStream();
3737

3838
// {% stopwatch 'bar' %}
39-
$name = $this->parser->getExpressionParser()->parseExpression();
39+
$name = method_exists($this->parser, 'parseExpression') ?
40+
$this->parser->parseExpression() :
41+
$this->parser->getExpressionParser()->parseExpression();
4042

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

src/Symfony/Bridge/Twig/TokenParser/TransDefaultDomainTokenParser.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ final class TransDefaultDomainTokenParser extends AbstractTokenParser
2525
{
2626
public function parse(Token $token): Node
2727
{
28-
$expr = $this->parser->getExpressionParser()->parseExpression();
28+
$expr = method_exists($this->parser, 'parseExpression') ?
29+
$this->parser->parseExpression() :
30+
$this->parser->getExpressionParser()->parseExpression();
2931

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

src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,33 @@ public function parse(Token $token): Node
3636
$vars = new ArrayExpression([], $lineno);
3737
$domain = null;
3838
$locale = null;
39+
$parseExpression = method_exists($this->parser, 'parseExpression')
40+
? $this->parser->parseExpression(...)
41+
: $this->parser->getExpressionParser()->parseExpression(...);
42+
3943
if (!$stream->test(Token::BLOCK_END_TYPE)) {
4044
if ($stream->test('count')) {
4145
// {% trans count 5 %}
4246
$stream->next();
43-
$count = $this->parser->getExpressionParser()->parseExpression();
47+
$count = $parseExpression();
4448
}
4549

4650
if ($stream->test('with')) {
4751
// {% trans with vars %}
4852
$stream->next();
49-
$vars = $this->parser->getExpressionParser()->parseExpression();
53+
$vars = $parseExpression();
5054
}
5155

5256
if ($stream->test('from')) {
5357
// {% trans from "messages" %}
5458
$stream->next();
55-
$domain = $this->parser->getExpressionParser()->parseExpression();
59+
$domain = $parseExpression();
5660
}
5761

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

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/notifier.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@
151151
{%- if message.getOptions() is null %}
152152
{{- '(empty)' }}
153153
{%- else %}
154-
{{- message.getOptions()|json_encode(constant('JSON_PRETTY_PRINT')) }}
154+
{{- message.getOptions().toArray()|json_encode(constant('JSON_PRETTY_PRINT')) }}
155155
{%- endif %}
156156
</pre>
157157
</div>

src/Symfony/Component/BrowserKit/AbstractBrowser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function xmlHttpRequest(string $method, string $uri, array $parameters =
163163
*/
164164
public function jsonRequest(string $method, string $uri, array $parameters = [], array $server = [], bool $changeHistory = true): Crawler
165165
{
166-
$content = json_encode($parameters);
166+
$content = json_encode($parameters, \JSON_PRESERVE_ZERO_FRACTION);
167167

168168
$this->setServerParameter('CONTENT_TYPE', 'application/json');
169169
$this->setServerParameter('HTTP_ACCEPT', 'application/json');

src/Symfony/Component/BrowserKit/Tests/AbstractBrowserTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ public function testXmlHttpRequest()
6868
public function testJsonRequest()
6969
{
7070
$client = $this->getBrowser();
71-
$client->jsonRequest('GET', 'http://example.com/', ['param' => 1], [], true);
71+
$client->jsonRequest('GET', 'http://example.com/', ['param' => 1, 'float' => 10.0], [], true);
7272
$this->assertSame('application/json', $client->getRequest()->getServer()['CONTENT_TYPE']);
7373
$this->assertSame('application/json', $client->getRequest()->getServer()['HTTP_ACCEPT']);
7474
$this->assertFalse($client->getServerParameter('CONTENT_TYPE', false));
7575
$this->assertFalse($client->getServerParameter('HTTP_ACCEPT', false));
76-
$this->assertSame('{"param":1}', $client->getRequest()->getContent());
76+
$this->assertSame('{"param":1,"float":10.0}', $client->getRequest()->getContent());
7777
}
7878

7979
public function testGetRequestWithIpAsHttpHost()

0 commit comments

Comments
 (0)