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

[HttpFoundation] Rename Request::getContentType() to getContentFormat() #46987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions 5 UPGRADE-6.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ FrameworkBundle
`Symfony\Component\Serializer\Normalizer\NormalizerInterface` or implement `NormalizerAwareInterface` instead
* Deprecate `AbstractController::renderForm()`, use `render()` instead

HttpFoundation
--------------

* Deprecate `Request::getContentType()`, use `getContentFormat()` instead

Mailer
--------

Expand Down
5 changes: 5 additions & 0 deletions 5 src/Symfony/Component/HttpFoundation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.2
---

* Deprecate the `Request::getContentType()` method and add `getContentFormat()` as replacement

6.1
---

Expand Down
12 changes: 12 additions & 0 deletions 12 src/Symfony/Component/HttpFoundation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -1332,8 +1332,20 @@ public function setRequestFormat(?string $format)

/**
* Gets the format associated with the request.
*
* @deprecated since Symfony 6.2, use getContentFormat() instead.
*/
public function getContentType(): ?string
{
trigger_deprecation('symfony/http-foundation', '6.2', 'The "%s::getContentType()" method is deprecated, use "getContentFormat()" instead.', get_debug_type($this));

return $this->getContentFormat();
}

/**
* Gets the format associated with the request.
*/
public function getContentFormat(): ?string
{
return $this->getFormat($this->headers->get('CONTENT_TYPE', ''));
}
Expand Down
13 changes: 13 additions & 0 deletions 13 src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\HttpFoundation\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
use Symfony\Component\HttpFoundation\Exception\JsonException;
use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
Expand All @@ -23,6 +24,8 @@

class RequestTest extends TestCase
{
use ExpectDeprecationTrait;

protected function tearDown(): void
{
Request::setTrustedProxies([], -1);
Expand Down Expand Up @@ -80,12 +83,22 @@ public function testIsNoCache()

public function testGetContentType()
{
$this->expectDeprecation('Since symfony/http-foundation 6.2: The "Symfony\Component\HttpFoundation\Request::getContentType()" method is deprecated, use "getContentFormat()" instead.');

$request = new Request();
$contentType = $request->getContentType();

$this->assertNull($contentType);
}

public function testGetContentFormat()
{
$request = new Request();
$contentFormat = $request->getContentFormat();

$this->assertNull($contentFormat);
}

public function testSetDefaultLocale()
{
$request = new Request();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function supports(Request $request): bool
{
return ($this->options['post_only'] ? $request->isMethod('POST') : true)
&& $this->httpUtils->checkRequestPath($request, $this->options['check_path'])
&& ($this->options['form_only'] ? 'form' === $request->getContentType() : true);
&& ($this->options['form_only'] ? 'form' === $request->getContentFormat() : true);
}

public function authenticate(Request $request): Passport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct(HttpUtils $httpUtils, UserProviderInterface $userPro

public function supports(Request $request): ?bool
{
if (!str_contains($request->getRequestFormat() ?? '', 'json') && !str_contains($request->getContentType() ?? '', 'json')) {
if (!str_contains($request->getRequestFormat() ?? '', 'json') && !str_contains($request->getContentFormat() ?? '', 'json')) {
return false;
}

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.