8000 Merge branch '5.4' into 6.2 · symfony/symfony@cbb8b9f · GitHub
[go: up one dir, main page]

Skip to content

Commit cbb8b9f

Browse files
Merge branch '5.4' into 6.2
* 5.4: [Cache] Removing null coalescing assignment operator on 5.4 [Cache] Fix storing binary keys when using pgsql [FrameworkBundle] Add missing monolog channel tag for messenger services [FrameworkBundle] Improve documentation about translation:extract --sort option [VarDumper] Disable links for IntelliJ platform [Notifier] Add bridge documentation [HttpClient] Add hint about `timeout` and `max_duration` options [HttpFoundation] Use separate caches for IpUtils checkIp4 and checkIp6 [FrameworkBundle] Fix wiring session.handler when handler_id is null [FrameworkBundle] Workflow - Fix LogicException about a wrong configuration of "enabled" node
2 parents eb9f258 + 0c07e5e commit cbb8b9f

File tree

19 files changed

+415
-22
lines changed

19 files changed

+415
-22
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected function configure()
8787
new InputOption('force', null, InputOption::VALUE_NONE, 'Should the extract be done'),
8888
new InputOption('clean', null, InputOption::VALUE_NONE, 'Should clean not found messages'),
8989
new InputOption('domain', null, InputOption::VALUE_OPTIONAL, 'Specify the domain to extract'),
90-
new InputOption('sort', null, InputOption::VALUE_OPTIONAL, 'Return list of messages sorted alphabetically', 'asc'),
90+
new InputOption('sort', null, InputOption::VALUE_OPTIONAL, 'Return list of messages sorted alphabetically (only works with --dump-messages)', 'asc'),
9191
new InputOption('as-tree', null, InputOption::VALUE_OPTIONAL, 'Dump the messages as a tree-like structure: The given value defines the level where to switch to inline YAML'),
9292
])
9393
->setHelp(<<<'EOF'
@@ -116,7 +116,6 @@ protected function configure()
116116
You can dump a tree-like structure using the yaml format with <comment>--as-tree</> flag:
117117
118118
<info>php %command.full_name% --force --format=yaml --as-tree=3 en AcmeBundle</info>
119-
<info>php %command.full_name% --force --format=yaml --sort=asc --as-tree=3 fr</info>
120119

121120
EOF
122121
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
358358

359359
foreach ($workflows as $key => $workflow) {
360360
if (isset($workflow['enabled']) && false === $workflow['enabled']) {
361-
throw new LogicException(sprintf('Cannot disable a single workflow. Remove the configuration for the workflow "%s" instead.', $workflow['name']));
361+
throw new LogicException(sprintf('Cannot disable a single workflow. Remove the configuration for the workflow "%s" instead.', $key));
362362
}
363363

364364
unset($workflows[$key]['enabled']);

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,11 +1180,8 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c
11801180

11811181
// session handler (the internal callback registered with PHP session management)
11821182
if (null === $config['handler_id']) {
1183-
// Set the handler class to be null
1184-
$container->getDefinition('session.storage.factory.native')->replaceArgument(1, null);
1185-
$container->getDefinition('session.storage.factory.php_bridge')->replaceArgument(0, null);
1186-
1187-
$container->setAlias('session.handler', 'session.handler.native_file');
1183+
$config['save_path'] = null;
1184+
$container->setA 10000 lias('session.handler', 'session.handler.native');
11881185
} else {
11891186
$container->resolveEnvPlaceholders($config['handler_id'], null, $usedEnvs);
11901187

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
->args([
142142
service('logger')->ignoreOnInvalid(),
143143
])
144+
->tag('monolog.logger', ['channel' => 'messenger'])
144145

145146
->set('messenger.transport.beanstalkd.factory', BeanstalkdTransportFactory::class)
146147

@@ -203,6 +204,7 @@
203204
service('logger')->ignoreOnInvalid(),
204205
])
205206
->tag('kernel.event_subscriber')
207+
->tag('monolog.logger', ['channel' => 'messenger'])
206208

207209
->set('messenger.listener.stop_worker_on_stop_exception_listener', StopWorkerOnCustomStopExceptionListener::class)
208210
->tag('kernel.event_subscriber')

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@
6969

7070
->alias(\SessionHandlerInterface::class, 'session.handler')
7171

72+
->set('session.handler.native', StrictSessionHandler::class)
73+
->args([
74+
inline_service(\SessionHandler::class),
75+
])
76+
7277
->set('session.handler.native_file', StrictSessionHandler::class)
7378
->args([
7479
inline_service(NativeFileSessionHandler::class)

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -660,9 +660,8 @@ public function testNullSessionHandler()
660660
{
661661
$container = $this->createContainerFromFile('session');
662662

663-
$this->assertNull($container->getDefinition('session.storage.factory.native')->getArgument(1));
664-
$this->assertNull($container->getDefinition('session.storage.factory.php_bridge')->getArgument(0));
665-
$this->assertSame('session.handler.native_file', (string) $container->getAlias('session.handler'));
663+
$this->assertNull($container->getParameter('session.save_path'));
664+
$this->assertSame('session.handler.native', (string) $container->getAlias('session.handler'));
666665

667666
$expected = ['session_factory', 'logger', 'session_collector'];
668667
$this->assertEquals($expected, array_keys($container->getDefinition('session_listener')->getArgument(0)->getValues()));

src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,22 @@ protected function doSave(array $values, int $lifetime): array|bool
309309
return $failed;
310310
}
311311

312+
/**
313+
* @internal
314+
*/
315+
protected function getId($key)
316+
{
317+
if ('pgsql' !== $this->platformName ??= $this->getPlatformName()) {
318+
return parent::getId($key);
319+
}
320+
321+
if (str_contains($key, "\0") || str_contains($key, '%') || !preg_match('//u', $key)) {
322+
$key = rawurlencode($key);
323+
}
324+
325+
return parent::getId($key);
326+
}
327+
312328
private function getPlatformName(): string
313329
{
314330
if (isset($this->platformName)) {

src/Symfony/Component/Cache/Adapter/PdoAdapter.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,22 @@ protected function doSave(array $values, int $lifetime): array|bool
336336
return $failed;
337337
}
338338

339+
/**
340+
* @internal
341+
*/
342+
protected function getId($key)
343+
{
344+
if ('pgsql' !== $this->driver ?? ($this->getConnection() ? $this->driver : null)) {
345+
return parent::getId($key);
346+
}
347+
348+
if (str_contains($key, "\0") || str_contains($key, '%') || !preg_match('//u', $key)) {
349+
$key = rawurlencode($key);
350+
}
351+
352+
return parent::getId($key);
353+
}
354+
339355
private function getConnection(): \PDO
340356
{
341357
if (!isset($this->conn)) {

src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,10 @@ private function generateItems(iterable $items, array &$keys): \Generator
317317
}
318318
}
319319

320-
private function getId(mixed $key)
320+
/**
321+
* @internal
322+
*/
323+
protected function getId(mixed $key)
321324
{
322325
if ($this->versioningIsEnabled && '' === $this->namespaceVersion) {
323326
$this->ids = [];

src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ public function setOptions(array $options)
8383
public function apply(string $text): string
8484
{
8585
$this->handlesHrefGracefully ??= 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR')
86-
&& (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100);
86+
&& (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100)
87+
&& !isset($_SERVER['IDEA_INITIAL_DIRECTORY']);
8788

8889
if (null !== $this->href && $this->handlesHrefGracefully) {
8990
$text = "\033]8;;$this->href\033\\$text\033]8;;\033\\";

src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,10 @@ public function testFormatterHasStyles()
244244
/**
245245
* @dataProvider provideDecoratedAndNonDecoratedOutput
246246
*/
247-
public function testNotDecoratedFormatter(string $input, string $expectedNonDecoratedOutput, string $expectedDecoratedOutput, string $terminalEmulator = 'foo')
247+
public function testNotDecoratedFormatterOnJediTermEmulator(string $input, string $expectedNonDecoratedOutput, string $expectedDecoratedOutput, bool $shouldBeJediTerm = false)
248248
{
249+
$terminalEmulator = $shouldBeJediTerm ? 'JetBrains-JediTerm' : 'Unknown';
250+
249251
$prevTerminalEmulator = getenv('TERMINAL_EMULATOR');
250252
putenv('TERMINAL_EMULATOR='.$terminalEmulator);
251253

@@ -257,6 +259,35 @@ public function testNotDecoratedFormatter(string $input, string $expectedNonDeco
257259
}
258260
}
259261

262+
/**
263+
* @dataProvider provideDecoratedAndNonDecoratedOutput
264+
*/
265+
public function testNotDecoratedFormatterOnIDEALikeEnvironment(string $input, string $expectedNonDecoratedOutput, string $expectedDecoratedOutput, bool $expectsIDEALikeTerminal = false)
266+
{
267+
// Backup previous env variable
268+
$previousValue = $_SERVER['IDEA_INITIAL_DIRECTORY'] ?? null;
269+
$hasPreviousValue = \array_key_exists('IDEA_INITIAL_DIRECTORY', $_SERVER);
270+
271+
if ($expectsIDEALikeTerminal) {
272+
$_SERVER['IDEA_INITIAL_DIRECTORY'] = __DIR__;
273+
} elseif ($hasPreviousValue) {
274+
// Forcibly remove the variable because the test runner may contain it
275+
unset($_SERVER['IDEA_INITIAL_DIRECTORY']);
276+
}
277+
278+
try {
279+
$this->assertEquals($expectedDecoratedOutput, (new OutputFormatter(true))->format($input));
280+
$this->assertEquals($expectedNonDecoratedOutput, (new OutputFormatter(false))->format($input));
281+
} finally {
282+
// Rollback previous env state
283+
if ($hasPreviousValue) {
284+
$_SERVER['IDEA_INITIAL_DIRECTORY'] = $previousValue;
285+
} else {
286+
unset($_SERVER['IDEA_INITIAL_DIRECTORY']);
287+
}
288+
}
289+
}
290+
260291
public static function provideDecoratedAndNonDecoratedOutput()
261292
{
262293
return [
@@ -267,7 +298,7 @@ public static function provideDecoratedAndNonDecoratedOutput()
267298
['<fg=red>some text with inline style</>', 'some text with inline style', "\033[31msome text with inline style\033[39m"],
268299
['<href=idea://open/?file=/path/SomeFile.php&line=12>some URL</>', 'some URL', "\033]8;;idea://open/?file=/path/SomeFile.php&line=12\033\\some URL\033]8;;\033\\"],
269300
['<href=https://example.com/\<woohoo\>>some URL with \<woohoo\></>', 'some URL with <woohoo>', "\033]8;;https://example.com/<woohoo>\033\\some URL with <woohoo>\033]8;;\033\\"],
270-
['<href=idea://open/?file=/path/SomeFile.php&line=12>some URL</>', 'some URL', 'some URL', 'JetBrains-JediTerm'],
301+
['<href=idea://open/?file=/path/SomeFile.php&line=12>some URL</>', 'some URL', 'some URL', true],
271302
];
272303
}
273304

src/Symfony/Component/HttpFoundation/IpUtils.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static function checkIp(string $requestIp, string|array $ips): bool
5959
*/
6060
public static function checkIp4(string $requestIp, string $ip): bool
6161
{
62-
$cacheKey = $requestIp.'-'.$ip;
62+
$cacheKey = $requestIp.'-'.$ip.'-v4';
6363
if (isset(self::$checkedIps[$cacheKey])) {
6464
return self::$checkedIps[$cacheKey];
6565
}
@@ -104,7 +104,7 @@ public static function checkIp4(string $requestIp, string $ip): bool
104104
*/
105105
public static function checkIp6(string $requestIp, string $ip): bool
106106
{
107-
$cacheKey = $requestIp.'-'.$ip;
107+
$cacheKey = $requestIp.'-'.$ip.'-v6';
108108
if (isset(self::$checkedIps[$cacheKey])) {
109109
return self::$checkedIps[$cacheKey];
110110
}

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NativeFileSessionHandler.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ public function __construct(string $savePath = null)
4545
throw new \RuntimeException(sprintf('Session Storage was not able to create directory "%s".', $baseDir));
4646
}
4747

48-
ini_set('session.save_path', $savePath);
49-
ini_set('session.save_handler', 'files');
48+
if ($savePath !== \ini_get('session.save_path')) {
49+
ini_set('session.save_path', $savePath);
50+
}
51+
if ('files' !== \ini_get('session.save_handler')) {
52+
ini_set('session.save_handler', 'files');
53+
}
5054
}
5155
}

src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ class IpUtilsTest extends TestCase
1919
{
2020
use ExpectDeprecationTrait;
2121

22+
public function testSeparateCachesPerProtocol()
23+
{
24+
$ip = '192.168.52.1';
25+
$subnet = '192.168.0.0/16';
26+
27+
$this->assertFalse(IpUtils::checkIp6($ip, $subnet));
28+
$this->assertTrue(IpUtils::checkIp4($ip, $subnet));
29+
30+
$ip = '2a01:198:603:0:396e:4789:8e99:890f';
31+
$subnet = '2a01:198:603:0::/65';
32+
33+
$this->assertFalse(IpUtils::checkIp4($ip, $subnet));
34+
$this->assertTrue(IpUtils::checkIp6($ip, $subnet));
35+
}
36+
2237
/**
2338
* @dataProvider getIpv4Data
2439
*/

src/Symfony/Component/Notifier/Bridge/Discord/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,58 @@ where:
1414
- `TOKEN` the secure token of the webhook (returned for Incoming Webhooks)
1515
- `ID` the id of the webhook
1616

17+
Adding Interactions to a Message
18+
--------------------------------
19+
20+
With a Discord message, you can use the `DiscordOptions` class to add some
21+
interactive options called Embed `elements`.
22+
23+
```php
24+
use Symfony\Component\Notifier\Bridge\Discord\DiscordOptions;
25+
use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordEmbed;
26+
use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordFieldEmbedObject;
27+
use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordFooterEmbedObject;
28+
use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordMediaEmbedObject;
29+
use Symfony\Component\Notifier\Message\ChatMessage;
30+
31+
$chatMessage = new ChatMessage('');
32+
33+
// Create Discord Embed
34+
$discordOptions = (new DiscordOptions())
35+
->username('connor bot')
36+
->addEmbed((new DiscordEmbed())
37+
->color(2021216)
38+
->title('New song added!')
39+
->thumbnail((new DiscordMediaEmbedObject())
40+
->url('https://i.scdn.co/image/ab67616d0000b2735eb27502aa5cb1b4c9db426b'))
41+
->addField((new DiscordFieldEmbedObject())
42+
->name('Track')
43+
->value('[Common Ground](https://open.spotify.com/track/36TYfGWUhIRlVjM8TxGUK6)')
44+
->inline(true)
45+
)
46+
->addField((new DiscordFieldEmbedObject())
47+
->name('Artist')
48+
->value('Alasdair Fraser')
49+
->inline(true)
50+
)
51+
->addField((new DiscordFieldEmbedObject())
52+
->name('Album')
53+
->value('Dawn Dance')
54+
->inline(true)
55+
)
56+
->footer((new DiscordFooterEmbedObject())
57+
->text('Added ...')
58+
->iconUrl('https://upload.wikimedia.org/wikipedia/commons/thumb/1/19/Spotify_logo_without_text.svg/200px-Spotify_logo_without_text.svg.png')
59+
)
60+
)
61+
;
62+
63+
// Add the custom options to the chat message and send the message
64+
$chatMessage->options($discordOptions);
65+
66+
$chatter->send($chatMessage);
67+
```
68+
1769
Resources
1870
---------
1971

0 commit comments

Comments
 (0)
0