[HttpFoundation] Allow to get all the mime types associated to a format in the Request

This commit is contained in:
Ener-Getick 2016-01-08 22:17:51 +01:00
parent 307ad07c61
commit 4618c9f9f8
2 changed files with 33 additions and 0 deletions

View File

@ -1310,6 +1310,22 @@ class Request
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.
*

View File

@ -330,6 +330,23 @@ class RequestTest extends \PHPUnit_Framework_TestCase
}
}
/**
* @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(