Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitc2c3b20

Browse 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 derivedfrom the mime type in the CONTENT_TYPE header.
1 parent22fd05a commitc2c3b20

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

‎UPGRADE-6.1.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
UPGRADE FROM 6.0 to 6.1
22
=======================
33

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

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

Lines 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

Lines 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
publicfunctiongetContentType(): ?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+
publicfunctiongetContentTypeFormat(): ?string
13291341
{
13301342
return$this->getFormat($this->headers->get('CONTENT_TYPE',''));
13311343
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespaceSymfony\Component\HttpFoundation\Tests;
1313

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

2425
class RequestTestextends TestCase
2526
{
27+
use ExpectDeprecationTrait;
28+
2629
protectedfunctiontearDown():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
publicfunctiontestGetContentType()
8288
{
89+
$this->expectDeprecation('Since symfony/http-foundation 6.1: The method "Symfony\Component\HttpFoundation\Request::getContentType" is deprecated, use "getContentTypeFormat" instead.');
8390
$request =newRequest();
91+
8492
$contentType =$request->getContentType();
8593

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

97+
publicfunctiontestGetContentTypeFormat()
98+
{
99+
$request =newRequest();
100+
$contentType =$request->getContentTypeFormat();
101+
102+
$this->assertNull($contentType);
103+
}
104+
89105
publicfunctiontestSetDefaultLocale()
90106
{
91107
$request =newRequest();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp