[HttpFoundation] Allow to get all the mime types associated to a format in the Request
This commit is contained in:
parent
307ad07c61
commit
4618c9f9f8
@ -1310,6 +1310,22 @@ class Request
|
|||||||
return isset(static::$formats[$format]) ? static::$formats[$format][0] : null;
|
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.
|
* Gets the format associated with the mime type.
|
||||||
*
|
*
|
||||||
|
@ -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()
|
public function getFormatToMimeTypeMapProvider()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
|
Reference in New Issue
Block a user