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 59db8a5

Browse filesBrowse files
committed
Rename getContentType to getContentTypeFormat
Resolves issue #39750. The method getContentType was confusing. This method does not return a mime type, but a mapped type name derived from the mime type in the CONTENT_TYPE header.
1 parent 22fd05a commit 59db8a5
Copy full SHA for 59db8a5

File tree

3 files changed

+33
-0
lines changed
Filter options

3 files changed

+33
-0
lines changed

‎src/Symfony/Component/HttpFoundation/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.1
5+
---
6+
7+
* Deprecate `Request::getContentType()`, use `Request::getContentTypeFormat()` instead`
8+
49
6.0
510
---
611

‎src/Symfony/Component/HttpFoundation/Request.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Request.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,8 +1324,20 @@ public function setRequestFormat(?string $format)
13241324

13251325
/**
13261326
* Gets the format associated with the request.
1327+
*
1328+
* @deprecated since Symfony 6.1, use getContentTypeFormat instead
13271329
*/
13281330
public function getContentType(): ?string
1331+
{
1332+
trigger_deprecation('symfony/http-foundation', '6.1', 'The method "%s" is deprecated, use "getContentTypeFormat" instead.', __METHOD__);
1333+
1334+
return $this->getContentTypeFormat();
1335+
}
1336+
1337+
/**
1338+
* Gets the format associated with the request.
1339+
*/
1340+
public function getContentTypeFormat(): ?string
13291341
{
13301342
return $this->getFormat($this->headers->get('CONTENT_TYPE', ''));
13311343
}

‎src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\HttpFoundation\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
1617
use Symfony\Component\HttpFoundation\Exception\JsonException;
1718
use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
@@ -23,6 +24,8 @@
2324

2425
class RequestTest extends TestCase
2526
{
27+
use ExpectDeprecationTrait;
28+
2629
protected function tearDown(): void
2730
{
2831
Request::setTrustedProxies([], -1);
@@ -78,14 +81,27 @@ public function testIsNoCache()
7881
$this->assertFalse($isNoCache);
7982
}
8083

84+
/**
85+
* @group legacy
86+
*/
8187
public function testGetContentType()
8288
{
89+
$this->expectDeprecation('Since symfony/http-foundation 6.1: The method "Symfony\Component\HttpFoundation\Request::getContentType" is deprecated, use "getContentTypeFormat" instead.');
8390
$request = new Request();
91+
8492
$contentType = $request->getContentType();
8593

8694
$this->assertNull($contentType);
8795
}
8896

97+
public function testGetContentTypeFormat()
98+
{
99+
$request = new Request();
100+
$contentType = $request->getContentTypeFormat();
101+
102+
$this->assertNull($contentType);
103+
}
104+
89105
public function testSetDefaultLocale()
90106
{
91107
$request = new Request();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.