Skip to content

Commit 13dd169

Browse files
committed
Merge branch '7.0' into 7.1
* 7.0: don't use deprecated and internal Twig functions [FrameworkBundle] Add missing webhook parsers [FrameworkBundle] Fix webhook parser service removal and add notifier parser service removal [Notifier][Clickatell] Fixed minor typo add missing translation [Messenger] Add missing Redis cleanup in tests Make sure Serializer::denormalize have show what exception it throws [WebProfilerBundle] Fix "Copy as cURL" dark style
2 parents 0d9562f + e9482f0 commit 13dd169

File tree

12 files changed

+98
-38
lines changed

12 files changed

+98
-38
lines changed

src/Symfony/Bridge/Twig/Node/SearchAndRenderBlockNode.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bridge\Twig\Node;
1313

1414
use Twig\Compiler;
15+
use Twig\Extension\CoreExtension;
1516
use Twig\Node\Expression\ArrayExpression;
1617
use Twig\Node\Expression\ConstantExpression;
1718
use Twig\Node\Expression\FunctionExpression;
@@ -50,7 +51,7 @@ public function compile(Compiler $compiler): void
5051
$labelIsExpression = false;
5152

5253
// Only insert the label into the array if it is not empty
53-
if (!twig_test_empty($label->getAttribute('value'))) {
54+
if (null !== $label->getAttribute('value') && false !== $label->getAttribute('value') && '' !== (string) $label->getAttribute('value')) {
5455
$originalVariables = $variables;
5556
$variables = new ArrayExpression([], $lineno);
5657
$labelKey = new ConstantExpression('label', $lineno);
@@ -97,7 +98,12 @@ public function compile(Compiler $compiler): void
9798

9899
// Check at runtime whether the label is empty.
99100
// If not, add it to the array at runtime.
100-
$compiler->raw('(twig_test_empty($_label_ = ');
101+
if (method_exists(CoreExtension::class, 'testEmpty')) {
102+
$compiler->raw('(CoreExtension::testEmpty($_label_ = ');
103+
} else {
104+
$compiler->raw('(twig_test_empty($_label_ = ');
105+
}
106+
101107
$compiler->subcompile($label);
102108
$compiler->raw(') ? [] : ["label" => $_label_])');
103109
}

src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode;
1616
use Twig\Compiler;
1717
use Twig\Environment;
18+
use Twig\Extension\CoreExtension;
1819
use Twig\Loader\LoaderInterface;
1920
use Twig\Node\Expression\ArrayExpression;
2021
use Twig\Node\Expression\ConditionalExpression;
@@ -226,8 +227,9 @@ public function testCompileLabelWithLabelThatEvaluatesToNull()
226227
// https://github.com/symfony/symfony/issues/5029
227228
$this->assertEquals(
228229
sprintf(
229-
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', (twig_test_empty($_label_ = ((true) ? (null) : (null))) ? [] : ["label" => $_label_]))',
230-
$this->getVariableGetter('form')
230+
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', (%s($_label_ = ((true) ? (null) : (null))) ? [] : ["label" => $_label_]))',
231+
$this->getVariableGetter('form'),
232+
method_exists(CoreExtension::class, 'testEmpty') ? 'CoreExtension::testEmpty' : 'twig_test_empty'
231233
),
232234
trim($compiler->compile($node)->getSource())
233235
);
@@ -263,8 +265,9 @@ public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes()
263265
// https://github.com/symfony/symfony/issues/5029
264266
$this->assertEquals(
265267
sprintf(
266-
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', ["foo" => "bar", "label" => "value in attributes"] + (twig_test_empty($_label_ = ((true) ? (null) : (null))) ? [] : ["label" => $_label_]))',
267-
$this->getVariableGetter('form')
268+
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', ["foo" => "bar", "label" => "value in attributes"] + (%s($_label_ = ((true) ? (null) : (null))) ? [] : ["label" => $_label_]))',
269+
$this->getVariableGetter('form'),
270+
method_exists(CoreExtension::class, 'testEmpty') ? 'CoreExtension::testEmpty' : 'twig_test_empty'
268271
),
269272
trim($compiler->compile($node)->getSource())
270273
);

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2586,13 +2586,15 @@ private function registerMailerConfiguration(array $config, ContainerBuilder $co
25862586

25872587
if ($webhookEnabled) {
25882588
$webhookRequestParsers = [
2589+
MailerBridge\Brevo\Webhook\BrevoRequestParser::class => 'mailer.webhook.request_parser.brevo',
25892590
MailerBridge\Mailgun\Webhook\MailgunRequestParser::class => 'mailer.webhook.request_parser.mailgun',
2591+
MailerBridge\Mailjet\Webhook\MailjetRequestParser::class => 'mailer.webhook.request_parser.mailjet',
25902592
MailerBridge\Postmark\Webhook\PostmarkRequestParser::class => 'mailer.webhook.request_parser.postmark',
25912593
MailerBridge\Sendgrid\Webhook\SendgridRequestParser::class => 'mailer.webhook.request_parser.sendgrid',
25922594
];
25932595

25942596
foreach ($webhookRequestParsers as $class => $service) {
2595-
$package = substr($service, \strlen('mailer.transport_factory.'));
2597+
$package = substr($service, \strlen('mailer.webhook.request_parser.'));
25962598

25972599
if (!ContainerBuilder::willBeAvailable(sprintf('symfony/%s-mailer', 'gmail' === $package ? 'google' : $package), $class, ['symfony/framework-bundle', 'symfony/mailer'])) {
25982600
$container->removeDefinition($service);
@@ -2803,6 +2805,19 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
28032805

28042806
if ($webhookEnabled) {
28052807
$loader->load('notifier_webhook.php');
2808+
2809+
$webhookRequestParsers = [
2810+
NotifierBridge\Twilio\Webhook\TwilioRequestParser::class => 'notifier.webhook.request_parser.twilio',
2811+
NotifierBridge\Vonage\Webhook\VonageRequestParser::class => 'notifier.webhook.request_parser.vonage',
2812+
];
2813+
2814+
foreach ($webhookRequestParsers as $class => $service) {
2815+
$package = substr($service, \strlen('notifier.webhook.request_parser.'));
2816+
2817+
if (!ContainerBuilder::willBeAvailable(sprintf('symfony/%s-notifier', $package), $class, ['symfony/framework-bundle', 'symfony/notifier'])) {
2818+
$container->removeDefinition($service);
2819+
}
2820+
}
28062821
}
28072822
}
28082823

src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_webhook.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@
1212
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
1313

1414
use Symfony\Component\Notifier\Bridge\Twilio\Webhook\TwilioRequestParser;
15+
use Symfony\Component\Notifier\Bridge\Vonage\Webhook\VonageRequestParser;
1516

1617
return static function (ContainerConfigurator $container) {
1718
$container->services()
1819
->set('notifier.webhook.request_parser.twilio', TwilioRequestParser::class)
1920
->alias(TwilioRequestParser::class, 'notifier.webhook.request_parser.twilio')
21+
22+
->set('notifier.webhook.request_parser.vonage', VonageRequestParser::class)
23+
->alias(VonageRequestParser::class, 'notifier.webhook.request_parser.vonage')
2024
;
2125
};

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,10 @@
186186
187187
copyToClipboardElement.textContent = `✅ Copied!`;
188188
copyToClipboardElement.disabled = true;
189-
copyToClipboardElement.classList.add('status-success');
190189
191190
setTimeout(() => {
192191
copyToClipboardElement.textContent = oldContent;
193192
copyToClipboardElement.disabled = false;
194-
copyToClipboardElement.classList.remove('status-success');
195193
}, 7000);
196194
});
197195
});

src/Symfony/Bundle/WebProfilerBundle/Tests/Twig/WebProfilerExtensionTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
use Symfony\Bundle\WebProfilerBundle\Twig\WebProfilerExtension;
1616
use Symfony\Component\VarDumper\Cloner\VarCloner;
1717
use Twig\Environment;
18-
use Twig\Extension\CoreExtension;
19-
use Twig\Extension\EscaperExtension;
2018

2119
class WebProfilerExtensionTest extends TestCase
2220
{
@@ -25,9 +23,6 @@ class WebProfilerExtensionTest extends TestCase
2523
*/
2624
public function testDumpHeaderIsDisplayed(string $message, array $context, bool $dump1HasHeader, bool $dump2HasHeader)
2725
{
28-
class_exists(CoreExtension::class); // Load twig_convert_encoding()
29-
class_exists(EscaperExtension::class); // Load twig_escape_filter()
30-
3126
$twigEnvironment = $this->mockTwigEnvironment();
3227
$varCloner = new VarCloner();
3328

src/Symfony/Bundle/WebProfilerBundle/Twig/WebProfilerExtension.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\VarDumper\Cloner\Data;
1515
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
1616
use Twig\Environment;
17+
use Twig\Extension\EscaperExtension;
1718
use Twig\Extension\ProfilerExtension;
1819
use Twig\Profiler\Profile;
1920
use Twig\TwigFunction;
@@ -78,12 +79,12 @@ public function dumpData(Environment $env, Data $data, int $maxDepth = 0): strin
7879

7980
public function dumpLog(Environment $env, string $message, Data $context = null): string
8081
{
81-
$message = twig_escape_filter($env, $message);
82+
$message = self::escape($env, $message);
8283
$message = preg_replace('/&quot;(.*?)&quot;/', '&quot;<b>$1</b>&quot;', $message);
8384

8485
$replacements = [];
8586
foreach ($context ?? [] as $k => $v) {
86-
$k = '{'.twig_escape_filter($env, $k).'}';
87+
$k = '{'.self::escape($env, $k).'}';
8788
if (str_contains($message, $k)) {
8889
$replacements[$k] = $v;
8990
}
@@ -104,4 +105,14 @@ public function getName(): string
104105
{
105106
return 'profiler';
106107
}
108+
109+
private static function escape(Environment $env, string $s): string
110+
{
111+
if (method_exists(EscaperExtension::class, 'escape')) {
112+
return EscaperExtension::escape($env, $s);
113+
}
114+
115+
// to be removed when support for Twig 3 is dropped
116+
return twig_escape_filter($env, $s);
117+
}
107118
}

src/Symfony/Component/Messenger/Bridge/Redis/Tests/Transport/RedisExtIntegrationTest.php

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -302,15 +302,19 @@ public function testLazy()
302302
$connection = Connection::fromDsn('redis://localhost/messenger-lazy?lazy=1', [], $redis);
303303

304304
$connection->add('1', []);
305-
$this->assertNotEmpty($message = $connection->get());
306-
$this->assertSame([
307-
'message' => json_encode([
308-
'body' => '1',
309-
'headers' => [],
310-
]),
311-
], $message['data']);
312-
$connection->reject($message['id']);
313-
$redis->del('messenger-lazy');
305+
306+
try {
307+
$this->assertNotEmpty($message = $connection->get());
308+
$this->assertSame([
309+
'message' => json_encode([
310+
'body' => '1',
311+
'headers' => [],
312+
]),
313+
], $message['data']);
314+
$connection->reject($message['id']);
315+
} finally {
316+
$redis->del('messenger-lazy');
317+
}
314318
}
315319

316320
public function testDbIndex()
@@ -337,13 +341,16 @@ public function testFromDsnWithMultipleHosts()
337341
public function testJsonError()
338342
{
339343
$redis = $this->createRedisClient();
340-
$connection = Connection::fromDsn('redis://localhost/json-error', [], $redis);
344+
$connection = Connection::fromDsn('redis://localhost/messenger-json-error', [], $redis);
341345
try {
342346
$connection->add("\xB1\x31", []);
347+
348+
$this->fail('Expected exception to be thrown.');
343349
} catch (TransportException $e) {
350+
$this->assertSame('Malformed UTF-8 characters, possibly incorrectly encoded', $e->getMessage());
351+
} finally {
352+
$redis->del('messenger-json-error');
344353
}
345-
346-
$this->assertSame('Malformed UTF-8 characters, possibly incorrectly encoded', $e->getMessage());
347354
}
348355

349356
public function testGetNonBlocking()
@@ -352,29 +359,41 @@ public function testGetNonBlocking()
352359

353360
$connection = Connection::fromDsn('redis://localhost/messenger-getnonblocking', ['sentinel_master' => null], $redis);
354361

355-
$this->assertNull($connection->get()); // no message, should return null immediately
356-
$connection->add('1', []);
357-
$this->assertNotEmpty($message = $connection->get());
358-
$connection->reject($message['id']);
359-
$redis->del('messenger-getnonblocking');
362+
try {
363+
$this->assertNull($connection->get()); // no message, should return null immediately
364+
$connection->add('1', []);
365+
$this->assertNotEmpty($message = $connection->get());
366+
$connection->reject($message['id']);
367+
} finally {
368+
$redis->del('messenger-getnonblocking');
369+
}
360370
}
361371

362372
public function testGetAfterReject()
363373
{
364374
$redis = $this->createRedisClient();
365375
$connection = Connection::fromDsn('redis://localhost/messenger-rejectthenget', ['sentinel_master' => null], $redis);
366376

367-
$connection->add('1', []);
368-
$connection->add('2', []);
377+
try {
378+
$connection->add('1', []);
379+
$connection->add('2', []);
369380

370-
$failing = $connection->get();
371-
$connection->reject($failing['id']);
381+
$failing = $connection->get();
382+
$connection->reject($failing['id']);
372383

384+
<<<<<<< HEAD
373385
$connection = Connection::fromDsn('redis://localhost/messenger-rejectthenget', ['sentinel_master' => null]);
374386

375387
$this->assertNotNull($connection->get());
376388

377389
$redis->del('messenger-rejectthenget');
390+
=======
391+
$connection = Connection::fromDsn('redis://localhost/messenger-rejectthenget', ['delete_after_ack' => true]);
392+
$this->assertNotNull($connection->get());
393+
} finally {
394+
$redis->del('messenger-rejectthenget');
395+
}
396+
>>>>>>> 5.4
378397
}
379398

380399
public function testItProperlyHandlesEmptyMessages()

src/Symfony/Component/Notifier/Bridge/Clickatell/ClickatellTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected function doSend(MessageInterface $message): SentMessage
7979
try {
8080
$statusCode = $response->getStatusCode();
8181
} catch (TransportExceptionInterface $e) {
82-
throw new TransportException('Could not reach the remote Clicktell server.', $response, 0, $e);
82+
throw new TransportException('Could not reach the remote Clickatell server.', $response, 0, $e);
8383
}
8484

8585
if (202 === $statusCode) {

src/Symfony/Component/Serializer/Serializer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ public function normalize(mixed $data, string $format = null, array $context = [
184184

185185
/**
186186
* @throws NotNormalizableValueException
187+
* @throws PartialDenormalizationException Occurs when one or more properties of $type fails to denormalize
187188
*/
188189
public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed
189190
{

0 commit comments

Comments
 (0)