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

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f8d82e4

Browse files
committed
Merge branch '6.0' into 6.1
* 6.0: remove no longer needed PHP version requirements from tests [Validator] [Security] Add Norwegian translations add tests covering union types in MessengerPass [HttpFoundation] Prevent BinaryFileResponse::prepare from adding content type if no content is sent
2 parents d6bde21 + a5c347b commit f8d82e4

File tree

11 files changed

+180
-34
lines changed

11 files changed

+180
-34
lines changed

src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -182,22 +182,25 @@ public function setContentDisposition(string $disposition, string $filename = ''
182182
*/
183183
public function prepare(Request $request): static
184184
{
185-
if (!$this->headers->has('Content-Type')) {
186-
$this->headers->set('Content-Type', $this->file->getMimeType() ?: 'application/octet-stream');
187-
}
185+
parent::prepare($request);
188186

189-
if ('HTTP/1.0' !== $request->server->get('SERVER_PROTOCOL')) {
190-
$this->setProtocolVersion('1.1');
187+
if ($this->isInformational() || $this->isEmpty()) {
188+
$this->maxlen = 0;
189+
190+
return $this;
191191
}
192192

193-
$this->ensureIEOverSSLCompatibility($request);
193+
if (!$this->headers->has('Content-Type')) {
194+
$this->headers->set('Content-Type', $this->file->getMimeType() ?: 'application/octet-stream');
195+
}
194196

195197
$this->offset = 0;
196198
$this->maxlen = -1;
197199

198200
if (false === $fileSize = $this->file->getSize()) {
199201
return $this;
200202
}
203+
$this->headers->remove('Transfer-Encoding');
201204
$this->headers->set('Content-Length', $fileSize);
202205

203206
if (!$this->headers->has('Accept-Ranges')) {
@@ -267,6 +270,10 @@ public function prepare(Request $request): static
267270
}
268271
}
269272

273+
if ($request->isMethod('HEAD')) {
274+
$this->maxlen = 0;
275+
}
276+
270277
return $this;
271278
}
272279

@@ -288,40 +295,42 @@ private function hasValidIfRangeHeader(?string $header): bool
288295
*/
289296
public function sendContent(): static
290297
{
291-
if (!$this->isSuccessful()) {
292-
return parent::sendContent();
293-
}
298+
try {
299+
if (!$this->isSuccessful()) {
300+
return parent::sendContent();
301+
}
294302

295-
if (0 === $this->maxlen) {
296-
return $this;
297-
}
303+
if (0 === $this->maxlen) {
304+
return $this;
305+
}
298306

299-
$out = fopen('php://output', 'w');
300-
$file = fopen($this->file->getPathname(), 'r');
307+
$out = fopen('php://output', 'w');
308+
$file = fopen($this->file->getPathname(), 'r');
301309

302-
ignore_user_abort(true);
310+
ignore_user_abort(true);
303311

304-
if (0 !== $this->offset) {
305-
fseek($file, $this->offset);
306-
}
312+
if (0 !== $this->offset) {
313+
fseek($file, $this->offset);
314+
}
307315

308-
$length = $this->maxlen;
309-
while ($length && !feof($file)) {
310-
$read = ($length > $this->chunkSize) ? $this->chunkSize : $length;
311-
$length -= $read;
316+
$length = $this->maxlen;
317+
while ($length && !feof($file)) {
318+
$read = ($length > $this->chunkSize) ? $this->chunkSize : $length;
319+
$length -= $read;
312320

313-
stream_copy_to_stream($file, $out, $read);
321+
stream_copy_to_stream($file, $out, $read);
314322

315-
if (connection_aborted()) {
316-
break;
323+
if (connection_aborted()) {
324+
break;
325+
}
317326
}
318-
}
319327

320-
fclose($out);
321-
fclose($file);
322-
323-
if ($this->deleteFileAfterSend && is_file($this->file->getPathname())) {
324-
unlink($this->file->getPathname());
328+
fclose($out);
329+
fclose($file);
330+
} finally {
331+
if ($this->deleteFileAfterSend && is_file($this->file->getPathname())) {
332+
unlink($this->file->getPathname());
333+
}
325334
}
326335

327336
return $this;

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,21 @@ public function testStream()
372372
$this->assertNull($response->headers->get('Content-Length'));
373373
}
374374

375+
public function testPrepareNotAddingContentTypeHeaderIfNoContentResponse()
376+
{
377+
$request = Request::create('/');
378+
$request->headers->set('If-Modified-Since', date('D, d M Y H:i:s').' GMT');
379+
380+
$response = new BinaryFileResponse(__DIR__.'/File/Fixtures/test.gif', 200, ['Content-Type' => 'application/octet-stream']);
381+
$response->setLastModified(new \DateTimeImmutable('-1 day'));
382+
$response->isNotModified($request);
383+
384+
$response->prepare($request);
385+
386+
$this->assertSame(BinaryFileResponse::HTTP_NOT_MODIFIED, $response->getStatusCode());
387+
$this->assertFalse($response->headers->has('Content-Type'));
388+
}
389+
375390
protected function provideResponse()
376391
{
377392
return new BinaryFileResponse(__DIR__.'/../README.md', 200, ['Content-Type' => 'application/octet-stream']);

src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,20 @@ private function guessHandledClasses(\ReflectionClass $handlerClass, string $ser
224224

225225
if ($type instanceof \ReflectionUnionType) {
226226
$types = [];
227+
$invalidTypes = [];
227228
foreach ($type->getTypes() as $type) {
228229
if (!$type->isBuiltin()) {
229230
$types[] = (string) $type;
231+
} else {
232+
$invalidTypes[] = (string) $type;
230233
}
231234
}
232235

233236
if ($types) {
234237
return ('__invoke' === $methodName) ? $types : array_fill_keys($types, $methodName);
235238
}
239+
240+
throw new RuntimeException(sprintf('Invalid handler service "%s": type-hint of argument "$%s" in method "%s::__invoke()" must be a class , "%s" given.', $serviceId, $parameters[0]->getName(), $handlerClass->getName(), implode('|', $invalidTypes)));
236241
}
237242

238243
if ($type->isBuiltin()) {

src/Symfony/Component/Messenger/Tests/DependencyInjection/MessengerPassTest.php

Expand all lines: src/Symfony/Component/Messenger/Tests/DependencyInjection/MessengerPassTest.php
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
use Symfony\Component\Messenger\Middleware\HandleMessageMiddleware;
4040
use Symfony\Component\Messenger\Middleware\MiddlewareInterface;
4141
use Symfony\Component\Messenger\Middleware\StackInterface;
42+
use Symfony\Component\Messenger\Tests\Fixtures\ChildDummyMessage;
4243
use Symfony\Component\Messenger\Tests\Fixtures\DummyCommand;
4344
use Symfony\Component\Messenger\Tests\Fixtures\DummyCommandHandler;
4445
use Symfony\Component\Messenger\Tests\Fixtures\DummyHandlerWithCustomMethods;
@@ -50,6 +51,8 @@
5051
use Symfony\Component\Messenger\Tests\Fixtures\SecondMessage;
5152
use Symfony\Component\Messenger\Tests\Fixtures\TaggedDummyHandler;
5253
use Symfony\Component\Messenger\Tests\Fixtures\TaggedDummyHandlerWithUnionTypes;
54+
use Symfony\Component\Messenger\Tests\Fixtures\UnionBuiltinTypeArgumentHandler;
55+
use Symfony\Component\Messenger\Tests\Fixtures\UnionTypeArgumentHandler;
5356
use Symfony\Component\Messenger\Tests\Fixtures\UnionTypeOneMessage;
5457
use Symfony\Component\Messenger\Tests\Fixtures\UnionTypeTwoMessage;
5558
use Symfony\Component\Messenger\Transport\Receiver\ReceiverInterface;
@@ -635,6 +638,37 @@ public function testBuiltinArgumentTypeHandler()
635638
(new MessengerPass())->process($container);
636639
}
637640

641+
public function testUnionTypeArgumentsTypeHandler()
642+
{
643+
$container = $this->getContainerBuilder($busId = 'message_bus');
644+
$container
645+
->register(UnionTypeArgumentHandler::class, UnionTypeArgumentHandler::class)
646+
->addTag('messenger.message_handler')
647+
;
648+
649+
(new MessengerPass())->process($container);
650+
651+
$handlersMapping = $container->getDefinition($busId.'.messenger.handlers_locator')->getArgument(0);
652+
653+
$this->assertArrayHasKey(ChildDummyMessage::class, $handlersMapping);
654+
$this->assertArrayHasKey(DummyMessage::class, $handlersMapping);
655+
$this->assertHandlerDescriptor($container, $handlersMapping, ChildDummyMessage::class, [UnionTypeArgumentHandler::class]);
656+
$this->assertHandlerDescriptor($container, $handlersMapping, DummyMessage::class, [UnionTypeArgumentHandler::class]);
657+
}
658+
659+
public function testUnionBuiltinArgumentTypeHandler()
660+
{
661+
$this->expectException(RuntimeException::class);
662+
$this->expectExceptionMessage(sprintf('Invalid handler service "%s": type-hint of argument "$message" in method "%s::__invoke()" must be a class , "string|int" given.', UnionBuiltinTypeArgumentHandler::class, UnionBuiltinTypeArgumentHandler::class));
663+
$container = $this->getContainerBuilder();
664+
$container
665+
->register(UnionBuiltinTypeArgumentHandler::class, UnionBuiltinTypeArgumentHandler::class)
666+
->addTag('messenger.message_handler')
667+
;
668+
669+
(new MessengerPass())->process($container);
670+
}
671+
638672
public function testNeedsToHandleAtLeastOneMessage()
639673
{
640674
$this->expectException(RuntimeException::class);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Messenger\Tests\Fixtures;
13+
14+
class UnionBuiltinTypeArgumentHandler
15+
{
16+
public function __invoke(string|int $message): void
17+
{
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Messenger\Tests\Fixtures;
13+
14+
class UnionTypeArgumentHandler
15+
{
16+
public function __invoke(ChildDummyMessage|DummyMessage $message): void
17+
{
18+
}
19+
}

src/Symfony/Component/Security/Core/Resources/translations/security.nb.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>Ugyldig eller utløpt påloggingskobling.</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>For mange mislykkede påloggingsforsøk, prøv igjen om %minutes% minutt.</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>For mange mislykkede påloggingsforsøk, prøv igjen om %minutes% minutter.</target>
80+
</trans-unit>
7381
</body>
7482
</file>
7583
</xliff>

src/Symfony/Component/Security/Core/Resources/translations/security.no.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>Ugyldig eller utløpt påloggingskobling.</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>For mange mislykkede påloggingsforsøk, prøv igjen om %minutes% minutt.</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>For mange mislykkede påloggingsforsøk, prøv igjen om %minutes% minutter.</target>
80+
</trans-unit>
7381
</body>
7482
</file>
7583
</xliff>

src/Symfony/Component/Validator/Resources/translations/validators.nb.xlf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,22 @@
386386
<source>This value is not a valid International Securities Identification Number (ISIN).</source>
387387
<target>Denne verdien er ikke et gyldig International Securities Identification Number (ISIN).</target>
388388
</trans-unit>
389+
<trans-unit id="100">
390+
<source>This value should be a valid expression.</source>
391+
<target>Denne verdien skal være et gyldig uttrykk.</target>
392+
</trans-unit>
393+
<trans-unit id="101">
394+
<source>This value is not a valid CSS color.</source>
395+
<target>Denne verdien er ikke en gyldig CSS-farge.</target>
396+
</trans-unit>
397+
<trans-unit id="102">
398+
<source>This value is not a valid CIDR notation.</source>
399+
<target>Denne verdien er ikke en gyldig CIDR-notasjon.</target>
400+
</trans-unit>
401+
<trans-unit id="103">
402+
<source>The value of the netmask should be between {{ min }} and {{ max }}.</source>
403+
<target>Verdien på nettmasken skal være mellom {{ min }} og {{ max }}.</target>
404+
</trans-unit>
389405
</body>
390406
</file>
391407
</xliff>

src/Symfony/Component/Validator/Resources/translations/validators.no.xlf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,22 @@
386386
<source>This value is not a valid International Securities Identification Number (ISIN).</source>
387387
<target>Denne verdien er ikke et gyldig International Securities Identification Number (ISIN).</target>
388388
</trans-unit>
389+
<trans-unit id="100">
390+
<source>This value should be a valid expression.</source>
391+
<target>Denne verdien skal være et gyldig uttrykk.</target>
392+
</trans-unit>
393+
<trans-unit id="101">
394+
<source>This value is not a valid CSS color.</source>
395+
<target>Denne verdien er ikke en gyldig CSS-farge.</target>
396+
</trans-unit>
397+
<trans-unit id="102">
398+
<source>This value is not a valid CIDR notation.</source>
399+
<target>Denne verdien er ikke en gyldig CIDR-notasjon.</target>
400+
</trans-unit>
401+
<trans-unit id="103">
402+
<source>The value of the netmask should be between {{ min }} and {{ max }}.</source>
403+
<target>Verdien på nettmasken skal være mellom {{ min }} og {{ max }}.</target>
404+
</trans-unit>
389405
</body>
390406
</file>
391407
</xliff>

src/Symfony/Component/Validator/Tests/Constraints/ValidTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ public function testGroupsAreNullByDefault()
3535
$this->assertNull($constraint->groups);
3636
}
3737

38-
/**
39-
* @requires PHP 8
40-
*/
4138
public function testAttributes()
4239
{
4340
$metadata = new ClassMetaData(ValidDummy::class);

0 commit comments

Comments
 (0)
0