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

Commit57b24fe

Browse files
committed
feature#45034 [HttpFoundation] Rename Request::getContentType to getContentTypeFormat (MarkPedron)
This PR was merged into the 6.2 branch.Discussion----------[HttpFoundation] Rename Request::getContentType to getContentTypeFormat| Q | A| ------------- | ---| Branch? | 6.1| Bug fix? | no| New feature? | yes| Deprecations? | yes| Tickets |Fix#39750| License | MIT| Doc PR | TODOCommits-------f545ed4 Rename getContentType to getContentTypeFormat
2 parents6920f1d +f545ed4 commit57b24fe

File tree

6 files changed

+48
-3
lines changed

6 files changed

+48
-3
lines changed

‎UPGRADE-6.2.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ FrameworkBundle
99
`Symfony\Component\Serializer\Normalizer\NormalizerInterface` or implement`NormalizerAwareInterface` instead
1010
* Deprecate`AbstractController::renderForm()`, use`render()` instead
1111

12+
HttpFoundation
13+
--------------
14+
15+
* Deprecate`Request::getContentType()`, use`Request::getContentTypeFormat()` instead
16+
1217
Mailer
1318
--------
1419

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Add stale while revalidate and stale if error cache header
88
* Allow dynamic session "ttl" when using a remote storage
9+
* Deprecate`Request::getContentType()`, use`Request::getContentTypeFormat()` instead
910

1011
6.0
1112
---

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,9 +1331,23 @@ public function setRequestFormat(?string $format)
13311331
}
13321332

13331333
/**
1334-
* Gets the format associated with the request.
1334+
* Gets the usual name of the format associated with the request's media type (provided in the Content-Type header).
1335+
*
1336+
* @deprecated since Symfony 6.2, use getContentTypeFormat instead
13351337
*/
13361338
publicfunctiongetContentType(): ?string
1339+
{
1340+
trigger_deprecation('symfony/http-foundation','6.2','The method "%s" is deprecated, use "getContentTypeFormat" instead.',__METHOD__);
1341+
1342+
return$this->getContentTypeFormat();
1343+
}
1344+
1345+
/**
1346+
* Gets the usual name of the format associated with the request's media type (provided in the Content-Type header).
1347+
*
1348+
* @see Request::$formats
1349+
*/
1350+
publicfunctiongetContentTypeFormat(): ?string
13371351
{
13381352
return$this->getFormat($this->headers->get('CONTENT_TYPE',''));
13391353
}

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

Lines changed: 22 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,33 @@ 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.2: 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+
$this->assertNull($request->getContentTypeFormat());
101+
102+
$server = ['HTTP_CONTENT_TYPE' =>'application/json'];
103+
$request =newRequest([], [], [], [], [],$server);
104+
$this->assertEquals('json',$request->getContentTypeFormat());
105+
106+
$server = ['HTTP_CONTENT_TYPE' =>'text/html'];
107+
$request =newRequest([], [], [], [], [],$server);
108+
$this->assertEquals('html',$request->getContentTypeFormat());
109+
}
110+
89111
publicfunctiontestSetDefaultLocale()
90112
{
91113
$request =newRequest();

‎src/Symfony/Component/Security/Http/Authenticator/FormLoginAuthenticator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function supports(Request $request): bool
7474
{
7575
return ($this->options['post_only'] ?$request->isMethod('POST') :true)
7676
&&$this->httpUtils->checkRequestPath($request,$this->options['check_path'])
77-
&& ($this->options['form_only'] ?'form' ===$request->getContentType() :true);
77+
&& ($this->options['form_only'] ?'form' ===(method_exists(Request::class,'getContentTypeFormat') ?$request->getContentTypeFormat() :$request->getContentType()) :true);
7878
}
7979

8080
publicfunctionauthenticate(Request$request):Passport

‎src/Symfony/Component/Security/Http/Authenticator/JsonLoginAuthenticator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ public function __construct(HttpUtils $httpUtils, UserProviderInterface $userPro
6363

6464
publicfunctionsupports(Request$request): ?bool
6565
{
66-
if (!str_contains($request->getRequestFormat() ??'','json') && !str_contains($request->getContentType() ??'','json')) {
66+
if (
67+
!str_contains($request->getRequestFormat() ??'','json')
68+
&& !str_contains((method_exists(Request::class,'getContentTypeFormat') ?$request->getContentTypeFormat() :$request->getContentType()) ??'','json')
69+
) {
6770
returnfalse;
6871
}
6972

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp