Skip to content

[HttpFoundation] Make some Request methods static #17379

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
6 changes: 3 additions & 3 deletions src/Symfony/Component/HttpFoundation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ public function getRealMethod()
*
* @return string The associated mime type (null if not found)
*/
public function getMimeType($format)
public static function getMimeType($format)
{
if (null === static::$formats) {
static::initializeFormats();
Expand Down Expand Up @@ -1333,7 +1333,7 @@ public static function getMimeTypes($format)
*
* @return string|null The format (null if not found)
*/
public function getFormat($mimeType)
public static function getFormat($mimeType)
{
if (false !== $pos = strpos($mimeType, ';')) {
$mimeType = substr($mimeType, 0, $pos);
Expand All @@ -1356,7 +1356,7 @@ public function getFormat($mimeType)
* @param string $format The format
* @param string|array $mimeTypes The associated mime types (the preferred one must be the first as it will be used as the content type)
*/
public function setFormat($format, $mimeTypes)
public static function setFormat($format, $mimeTypes)
{
if (null === static::$formats) {
static::initializeFormats();
Expand Down
16 changes: 6 additions & 10 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,20 +303,18 @@ public function testDuplicateWithFormat()
*/
public function testGetFormatFromMimeType($format, $mimeTypes)
{
$request = new Request();
foreach ($mimeTypes as $mime) {
$this->assertEquals($format, $request->getFormat($mime));
$this->assertEquals($format, Request::getFormat($mime));
}
$request->setFormat($format, $mimeTypes);
Request::setFormat($format, $mimeTypes);
foreach ($mimeTypes as $mime) {
$this->assertEquals($format, $request->getFormat($mime));
$this->assertEquals($format, Request::getFormat($mime));
}
}

public function testGetFormatFromMimeTypeWithParameters()
{
$request = new Request();
$this->assertEquals('json', $request->getFormat('application/json; charset=utf-8'));
$this->assertEquals('json', Request::getFormat('application/json; charset=utf-8'));
}

/**
Expand All @@ -325,8 +323,7 @@ public function testGetFormatFromMimeTypeWithParameters()
public function testGetMimeTypeFromFormat($format, $mimeTypes)
{
if (null !== $format) {
$request = new Request();
$this->assertEquals($mimeTypes[0], $request->getMimeType($format));
$this->assertEquals($mimeTypes[0], Request::getMimeType($format));
}
}

Expand All @@ -342,8 +339,7 @@ public function testGetMimeTypesFromFormat($format, $mimeTypes)

public function testGetMimeTypesFromInexistentFormat()
{
$request = new Request();
$this->assertNull($request->getMimeType('foo'));
$this->assertNull(Request::getMimeType('foo'));
$this->assertEquals(array(), Request::getMimeTypes('foo'));
}

Expand Down