Skip to content

Commit

Permalink
[HttpFoundation] Allow to get all the mime types associated to a form…
Browse files Browse the repository at this point in the history
…at in the Request
  • Loading branch information
GuilhemN committed Jan 12, 2016
1 parent 307ad07 commit 4618c9f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Symfony/Component/HttpFoundation/Request.php
Expand Up @@ -1310,6 +1310,22 @@ public function getMimeType($format)
return isset(static::$formats[$format]) ? static::$formats[$format][0] : null;
}

/**
* Gets the mime types associated with the format.
*
* @param string $format The format
*
* @return array The associated mime types
*/
public static function getMimeTypes($format)
{
if (null === static::$formats) {
static::initializeFormats();
}

return isset(static::$formats[$format]) ? static::$formats[$format] : array();
}

/**
* Gets the format associated with the mime type.
*
Expand Down
17 changes: 17 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Expand Up @@ -330,6 +330,23 @@ public function testGetMimeTypeFromFormat($format, $mimeTypes)
}
}

/**
* @dataProvider getFormatToMimeTypeMapProvider
*/
public function testGetMimeTypesFromFormat($format, $mimeTypes)
{
if (null !== $format) {
$this->assertEquals($mimeTypes, Request::getMimeTypes($format));
}
}

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

public function getFormatToMimeTypeMapProvider()
{
return array(
Expand Down

0 comments on commit 4618c9f

Please sign in to comment.