Skip to content

Commit 0ea77d7

Browse files
committed
Deprecate null $format argument to Request::getFormat() and ::setFormat().
1 parent da42259 commit 0ea77d7

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

UPGRADE-7.4.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ HttpFoundation
9696
* Deprecate using `Request::sendHeaders()` after headers have already been sent; use a `StreamedResponse` instead
9797
* Deprecate method `Request::get()`, use properties `->attributes`, `query` or `request` directly instead
9898
* Deprecate HTTP method override for methods GET, HEAD, CONNECT and TRACE; it will be ignored in Symfony 8.0
99+
* Deprecate null `$format` argument to `Request::getFormat()` and `Request::setFormat()`
99100

100101
HttpKernel
101102
----------

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,11 +1311,15 @@ public static function getMimeTypes(string $format): array
13111311
* - return the MIME subtype (without "x-" prefix), provided it does not
13121312
* contain a "+" (e.g. "application/x-yaml" → "yaml", "text/csv" → "csv").
13131313
*
1314-
* @param string|null $mimeType The mime type to check
1315-
* @param bool $subtypeFallback Whether to fall back to the subtype if no exact match is found
1314+
* @param string $mimeType The mime type to check
1315+
* @param bool $subtypeFallback Whether to fall back to the subtype if no exact match is found
13161316
*/
13171317
public function getFormat(?string $mimeType/* , bool $subtypeFallback = false */): ?string
13181318
{
1319+
if (null === $mimeType) {
1320+
trigger_deprecation('symfony/http-foundation', '7.4', 'Passing "null" as the first argument of "%s()" is deprecated. The argument will be non-nullable in Symfony 8.0.', __METHOD__);
1321+
}
1322+
13191323
$subtypeFallback = 2 <= \func_num_args() ? func_get_arg(1) : false;
13201324
$canonicalMimeType = null;
13211325
if ($mimeType && false !== $pos = strpos($mimeType, ';')) {
@@ -1369,6 +1373,7 @@ public function getFormat(?string $mimeType/* , bool $subtypeFallback = false */
13691373
/**
13701374
* Associates a format with mime types.
13711375
*
1376+
* @param string $format The format to set
13721377
* @param string|string[] $mimeTypes The associated mime types (the preferred one must be the first as it will be used as the content type)
13731378
*/
13741379
public function setFormat(?string $format, string|array $mimeTypes): void
@@ -1377,6 +1382,10 @@ public function setFormat(?string $format, string|array $mimeTypes): void
13771382
static::initializeFormats();
13781383
}
13791384

1385+
if (null === $format) {
1386+
trigger_deprecation('symfony/http-foundation', '7.4', 'Passing "null" as the first argument of "%s()" is deprecated. The argument will be non-nullable in Symfony 8.0.', __METHOD__);
1387+
}
1388+
13801389
static::$formats[$format ?? ''] = (array) $mimeTypes;
13811390
}
13821391

0 commit comments

Comments
 (0)