8000 Merge branch '6.0' into 6.1 · symfony/symfony@6037db9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6037db9

Browse files
Merge branch '6.0' into 6.1
* 6.0: [HttpKernel] Fix empty request stack when terminating with exception [HttpKernel] Remove EOL when using error_log() in HttpKernel Logger [HttpClient] Add test case for seeking into the content of RetryableHttpClient responses [HttpClient] Fix buffering after calling AsyncContext::passthru() s/annd/and s/gargage/garbage [Console] Fix error output on windows cli Reserve keys when using numeric ones add missing Azerbaijani translations fix few typos/inconsistencies in latvian translations Fix TypeError in Router when using UrlGenerator [Messenger] Fix amqp socket lost fix: use message object from event
2 parents 4ed4367 + 7594b48 commit 6037db9

File tree

19 files changed

+173
-27
lines changed

19 files changed

+173
-27
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ protected function doInvalidate(array $tagIds): bool
203203
// and removes the linked items. When the set is still not empty after
204204
// the scan, it means we're in cluster mode and that the linked items
205205
// are on other nodes: we move the links to a temporary set and we
206-
// gargage collect that set from the client side.
206+
// garbage collect that set from the client side.
207207

208208
$lua = <<<'EOLUA'
209209
redis.replicate_commands()

src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,19 @@ public function testNullByteInKey()
341341

342342
$this->assertSame(123, $cache->getItem("a\0b")->get());
343343
}
344+
345+
public function testNumericKeysWorkAfterMemoryLeakPrevention()
346+
{
347+
$cache = $this->createCachePool(0, __FUNCTION__);
348+
349+
for ($i = 0; $i < 1001; ++$i) {
350+
$cacheItem = $cache->getItem((string) $i);
351+
$cacheItem->set('value-'.$i);
352+
$cache->save($cacheItem);
353+
}
354+
355+
$this->assertEquals('value-50', $cache->getItem((string) 50)->get());
356+
}
344357
}
345358

346359
class NotUnserializable

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ private function getId(mixed $key)
373373
$this->ids[$key] = $key;
374374

375375
if (\count($this->ids) > 1000) {
376-
array_splice($this->ids, 0, 500); // stop memory leak if there are many keys
376+
$this->ids = \array_slice($this->ids, 500, null, true); // stop memory leak if there are many keys
377377
}
378378

379379
if (null === $this->maxIdLength) {

src/Symfony/Component/Console/Application.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public function doRun(InputInterface $input, OutputInterface $output)
276276
$alternative = $alternatives[0];
277277

278278
$style = new SymfonyStyle($input, $output);
279-
$style->block(sprintf("\nCommand \"%s\" is not defined.\n", $name), null, 'error');
279+
$style->block(sprintf('Command "%s" is not defined.', $name), null, 'error', ' ', true);
280280
if (!$style->confirm(sprintf('Do you want to run "%s" instead? ', $alternative), false)) {
281281
if (null !== $this->dispatcher) {
282282
$event = new ConsoleErrorEvent($input, $output, $e);
@@ -907,11 +907,21 @@ protected function configureIO(InputInterface $input, OutputInterface $output)
907907
}
908908

909909
switch ($shellVerbosity = (int) getenv('SHELL_VERBOSITY')) {
910-
case -1: $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); break;
911-
case 1: $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); break;
912-
case 2: $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); break;
913-
case 3: $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG); break;
914-
default: $shellVerbosity = 0; break;
910+
case -1:
911+
$output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
912+
break;
913+
case 1:
914+
$output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
915+
break;
916+
case 2:
917+
$output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE);
918+
break;
919+
case 3:
920+
$output->setVerbosity(OutputInterface::VERBOSITY_DEBUG);
921+
break;
922+
default:
923+
$shellVerbosity = 0;
924+
break;
915925
}
916926

917927
if (true === $input->hasParameterOption(['--quiet', '-q'], true)) {

src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* A list of choices with arbitrary data types.
1616
*
1717
* The user of this class is responsible for assigning string values to the
18-
* choices annd for their uniqueness.
18+
* choices and for their uniqueness.
1919
* Both the choices and their values are passed to the constructor.
2020
* Each choice must have a corresponding value (with the same key) in
2121
* the values array.

src/Symfony/Component/Form/Resources/translations/validators.lv.xlf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
</trans-unit>
133133
<trans-unit id="128">
134134
<source>Please enter a valid week.</source>
135-
<target>Lūdzu, ievadiet derīgu nedeļu.</target>
135+
<target>Lūdzu, ievadiet derīgu nedēļu.</target>
136136
</trans-unit>
137137
</body>
138138
</file>

src/Symfony/Component/HttpClient/Response/AsyncContext.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,15 @@ public function replaceResponse(ResponseInterface $response): ResponseInterface
184184

185185
/**
186186
* Replaces or removes the chunk filter iterator.
187+
*
188+
* @param ?callable(ChunkInterface, self): ?\Iterator $passthru
187189
*/
188190
public function passthru(callable $passthru = null): void
189191
{
190-
$this->passthru = $passthru;
192+
$this->passthru = $passthru ?? static function ($chunk, $context) {
193+
$context->passthru = null;
194+
195+
yield $chunk;
196+
};
191197
}
192198
}

src/Symfony/Component/HttpClient/Tests/RetryableHttpClientTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,22 @@ public function log($level, $message, array $context = []): void
225225
$this->assertNotNull($delay);
226226
$this->assertSame((int) ($retryAfter * 1000), $delay);
227227
}
228+
229+
public function testRetryOnErrorAssertContent()
230+
{
231+
$client = new RetryableHttpClient(
232+
new MockHttpClient([
233+
new MockResponse('', ['http_code' => 500]),
234+
new MockResponse('Test out content', ['http_code' => 200]),
235 10000 +
]),
236+
new GenericRetryStrategy([500], 0),
237+
1
238+
);
239+
240+
$response = $client->request('GET', 'http://example.com/foo-bar');
241+
242+
self::assertSame(200, $response->getStatusCode());
243+
self::assertSame('Test out content', $response->getContent());
244+
self::assertSame('Test out content', $response->getContent(), 'Content should be buffered');
245+
}
228246
}

src/Symfony/Component/HttpKernel/HttpKernel.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,17 @@ public function terminateWithException(\Throwable $exception, Request $request =
106106
throw $exception;
107107
}
108108

109-
$response = $this->handleThrowable($exception, $request, self::MAIN_REQUEST);
109+
if ($pop = $request !== $this->requestStack->getMainRequest()) {
110+
$this->requestStack->push($request);
111+
}
112+
113+
try {
114+
$response = $this->handleThrowable($exception, $request, self::MAIN_REQUEST);
115+
} finally {
116+
if ($pop) {
117+
$this->requestStack->pop();
118+
}
119+
}
110120

111121
$response->sendHeaders();
112122
$response->sendContent();

src/Symfony/Component/HttpKernel/Log/Logger.php

Lines changed 10000 : 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@ public function __construct(string $minLevel = null, $output = null, callable $f
4949

5050
if (isset($_ENV['SHELL_VERBOSITY']) || isset($_SERVER['SHELL_VERBOSITY'])) {
5151
switch ((int) ($_ENV['SHELL_VERBOSITY'] ?? $_SERVER['SHELL_VERBOSITY'])) {
52-
case -1: $minLevel = LogLevel::ERROR; break;
53-
case 1: $minLevel = LogLevel::NOTICE; break;
54-
case 2: $minLevel = LogLevel::INFO; break;
55-
case 3: $minLevel = LogLevel::DEBUG; break;
52+
case -1: $minLevel = LogLevel::ERROR;
53+
break;
54+
case 1: $minLevel = LogLevel::NOTICE;
55+
break;
56+
case 2: $minLevel = LogLevel::INFO;
57+
break;
58+
case 3: $minLevel = LogLevel::DEBUG;
59+
break;
5660
}
5761
}
5862
}
@@ -83,7 +87,7 @@ public function log($level, $message, array $context = []): void
8387

8488
$formatter = $this->formatter;
8589
if ($this->handle) {
86-
@fwrite($this->handle, $formatter($level, $message, $context));
90+
@fwrite($this->handle, $formatter($level, $message, $context).\PHP_EOL);
8791
} else {
8892
error_log($formatter($level, $message, $context, false));
8993
}
@@ -108,7 +112,7 @@ private function format(string $level, string $message, array $context, bool $pr
108112
$message = strtr($message, $replacements);
109113
}
110114

111-
$log = sprintf('[%s] %s', $level, $message).\PHP_EOL;
115+
$log = sprintf('[%s] %s', $level, $message);
112116
if ($prefixDate) {
113117
$log = date(\DateTime::RFC3339).' '.$log;
114118
}

src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,22 @@ public function testTerminate()
341341
$this->assertEquals($response, $capturedResponse);
342342
}
343343

344+
public function testTerminateWithException()
345+
{
346+
$dispatcher = new EventDispatcher();
347+
$requestStack = new RequestStack();
348+
$kernel = $this->getHttpKernel($dispatcher, null, $requestStack);
349+
350+
$dispatcher->addListener(KernelEvents::EXCEPTION, function (ExceptionEvent $event) use (&$capturedRequest, $requestStack) {
351+
$capturedRequest = $requestStack->getCurrentRequest();
352+
$event->setResponse(new Response());
353+
});
354+
355+
$kernel->terminateWithException(new \Exception('boo'), $request = Request::create('/'));
356+
$this->assertSame($request, $capturedRequest);
357+
$this->assertNull($requestStack->getCurrentRequest());
358+
}
359+
344360
public function testVerifyRequestStackPushPopDuringHandle()
345361
{
346362
$request = new Request();

src/Symfony/Component/HttpKernel/Tests/Log/LoggerTest.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected function tearDown(): void
4848
public static function assertLogsMatch(array $expected, array $given)
4949
{
5050
foreach ($given as $k => $line) {
51-
self::assertThat(1 === preg_match('/[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}[\+-][0-9]{2}:[0-9]{2} '.preg_quote($expected[$k]).'/', $line), self::isTrue(), "\"$line\" do not match expected pattern \"$expected[$k]\"");
51+
self::assertSame(1, preg_match('/[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}[\+-][0-9]{2}:[0-9]{2} '.preg_quote($expected[$k]).'/', $line), "\"$line\" do not match expected pattern \"$expected[$k]\"");
5252
}
5353
}
5454

@@ -186,7 +186,7 @@ public function testContextExceptionKeyCanBeExceptionOrOtherValues()
186186
public function testFormatter()
187187
{
188188
$this->logger = new Logger(LogLevel::DEBUG, $this->tmpFile, function ($level, $message, $context) {
189-
return json_encode(['level' => $level, 'message' => $message, 'context' => $context]).\PHP_EOL;
189+
return json_encode(['level' => $level, 'message' => $message, 'context' => $context]);
190190
});
191191

192192
$this->logger->error('An error', ['foo' => 'bar']);
@@ -196,6 +196,26 @@ public function testFormatter()
196196
'{"level":"warning","message":"A warning","context":{"baz":"bar"}}',
197197
], $this->getLogs());
198198
}
199+
200+
public function testLogsWithoutOutput()
201+
{
202+
$oldErrorLog = ini_set('error_log', $this->tmpFile);
203+
204+
$logger = new Logger();
205+
$logger->error('test');
206+
$logger->critical('test');
207+
208+
$expected = [
209+
'[error] test',
210+
'[critical] test',
211+
];
212+
213+
foreach ($this->getLogs() as $k => $line) {
214+
$this->assertSame(1, preg_match('/\[[\w\/\-: ]+\] '.preg_quote($expected[$k]).'/', $line), "\"$line\" do not match expected pattern \"$expected[$k]\"");
215+
}
216+
217+
ini_set('error_log', $oldErrorLog);
218+
}
199219
}
200220

201221
class DummyTest

src/Symfony/Component/Mailer/Transport/AbstractTransport.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public function send(RawMessage $message, Envelope $envelope = null): ?SentMessa
6262
$event = new MessageEvent($message, $envelope, (string) $this);
6363
$this->dispatcher->dispatch($event);
6464
$envelope = $event->getEnvelope();
65+
$message = $event->getMessage();
6566
}
6667

6768
$message = new SentMessage($message, $envelope);

src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ class Connection
9191

9292
private \AMQPExchange $amqpDelayExchange;
9393

94+
/**
95+
* @var int
96+
*/
97+
private $lastActivityTime = 0;
98+
9499
public function __construct(array $connectionOptions, array $exchangeOptions, array $queuesOptions, AmqpFactory $amqpFactory = null)
95100
{
96101
if (!\extension_loaded('amqp')) {
@@ -332,6 +337,8 @@ private function publishOnExchange(\AMQPExchange $exchange, string $body, string
332337
$attributes['delivery_mode'] = $attributes['delivery_mode'] ?? 2;
333338
$attributes['timestamp'] = $attributes['timestamp'] ?? time();
334339

340+
$this->lastActivityTime = time();
341+
335342
$exchange->publish(
336343
$body,
337344
$routingKey,
@@ -495,6 +502,11 @@ static function (): bool {
495502
}
496503
);
497504
}
505+
506+
$this->lastActivityTime = time();
507+
} elseif (0 < ($this->connectionOptions['heartbeat'] ?? 0) && time() > $this->lastActivityTime + 2 * $this->connectionOptions['heartbeat']) {
508+
$disconnectMethod = 'true' === ($this->connectionOptions['persistent'] ?? 'false') ? 'pdisconnect' : 'disconnect';
509+
$this->amqpChannel->getConnection()->{$disconnectMethod}();
498510
}
499511

500512
return $this->amqpChannel;

src/Symfony/Component/Routing/Router.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,12 @@ public function getGenerator(): UrlGeneratorInterface
299299

300300
if (null === $this->options['cache_dir']) {
301301
$routes = $this->getRouteCollection();
302-
$aliases = [];
303302
$compiled = is_a($this->options['generator_class'], CompiledUrlGenerator::class, true);
304303
if ($compiled) {
305304
$generatorDumper = new CompiledUrlGeneratorDumper($routes);
306-
$routes = $generatorDumper->getCompiledRoutes();
307-
$aliases = $generatorDumper->getCompiledAliases();
305+
$routes = array_merge($generatorDumper->getCompiledRoutes(), $generatorDumper->getCompiledAliases());
308306
}
309-
$this->generator = new $this->options['generator_class'](array_merge($routes, $aliases), $this->context, $this->logger, $this->defaultLocale);
307+
$this->generator = new $this->options['generator_class']($routes, $this->context, $this->logger, $this->defaultLocale);
310308
} else {
311309
$cache = $this->getConfigCacheFactory()->cache($this->options['cache_dir'].'/url_generating_routes.php',
312310
function (ConfigCacheInterface $cache) {

src/Symfony/Component/Routing/Tests/RouterTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Config\Loader\LoaderInterface;
1616
use Symfony\Component\HttpFoundation\Request;
17+
use Symfony\Component\Routing\Generator\CompiledUrlGenerator;
1718
use Symfony\Component\Routing\Generator\UrlGenerator;
1819
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1920
use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
@@ -124,11 +125,24 @@ public function testGeneratorIsCreatedIfCacheIsNotConfigured()
124125
{
125126
$this->router->setOption('cache_dir', null);
126127

128+
$this->loader->expects($this->once())
129+
->method('load')->with('routing.yml', null)
130+
->willReturn(new RouteCollection());
131+
132+
$this->assertInstanceOf(CompiledUrlGenerator::class, $this->router->getGenerator());
133+
}
134+
135+
public function testGeneratorIsCreatedIfCacheIsNotConfiguredNotCompiled()
136+
{
137+
$this->router->setOption('cache_dir', null);
138+
$this->router->setOption('generator_class', UrlGenerator::class);
139+
127140
$this->loader->expects($this->once())
128141
->method('load')->with('routing.yml', null)
129142
->willReturn(new RouteCollection());
130143

131144
$this->assertInstanceOf(UrlGenerator::class, $this->router->getGenerator());
145+
$this->assertNotInstanceOf(CompiledUrlGenerator::class, $this->router->getGenerator());
132146
}
133147

134148
public function testMatchRequestWithUrlMatcherInterface()

src/Symfony/Component/Security/Core/Resources/translations/security.az.xlf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@
7070
<source>Invalid or expired login link.</source>
7171
<target>Yanlış və ya müddəti keçmiş giriş keçidi.</target>
7272
</trans-unit>
73+
<trans-unit id="19">
74+
<source>Too many failed login attempts, please try again in %minutes% minute.</source>
75+
<target>Həddindən artıq uğursuz giriş cəhdi, lütfən %minutes% dəqiqə ərzində yenidən yoxlayın.</target>
76+
</trans-unit>
77+
<trans-unit id="20">
78+
<source>Too many failed login attempts, please try again in %minutes% minutes.</source>
79+
<target>Həddindən artıq uğursuz giriş cəhdi, lütfən %minutes% dəqiqə ərzində yenidən yoxlayın.</target>
80+
</trans-unit>
7381
</body>
7482
</file>
7583
</xliff>

src/Symfony/Component/Security/Core/Resources/translations/security.lv.xlf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</trans-unit>
2525
<trans-unit id="6">
2626
<source>Not privileged to request the resource.</source>
27-
<target>Nav tiesību ši resursa izsaukšanai.</target>
27+
<target>Nav tiesību šī resursa izsaukšanai.</target>
2828
</trans-unit>
2929
<trans-unit id="7">
3030
<source>Invalid CSRF token.</source>
@@ -64,11 +64,11 @@
6464
</trans-unit>
6565
<trans-unit id="17">
6666
<source>Too many failed login attempts, please try again later.</source>
67-
<target>Pārāk daudz atteiktu ieejas mēģinājumu, lūdzu, mēģiniet vēlreiz vēlāk.</target>
67+
<target>Pārāk daudz atteiktu autentifikācijas mēģinājumu, lūdzu, mēģiniet vēlreiz vēlāk.</target>
6868
</trans-unit>
6969
<trans-unit id="18">
7070
<source>Invalid or expired login link.</source>
71-
<target>Ieejas saite ir nederīga vai arī tai ir beidzies derīguma termiņš.</target>
71+
<target>Autentifikācijas saite ir nederīga vai arī tai ir beidzies derīguma termiņš.</target>
7272
</trans-unit>
7373
<trans-unit id="19">
7474
<source>Too many failed login attempts, please try again in %minutes% minute.</source>

0 commit comments

Comments
 (0)
0