8000 [HttpFoundation] Allow to get all the mime types associated to a form… · symfony/symfony@4618c9f · GitHub
[go: up one dir, main page]

Skip to content

Commit 4618c9f

Browse files
committed
[HttpFoundation] Allow to get all the mime types associated to a format in the Request
1 parent 307ad07 commit 4618c9f

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,22 @@ public function getMimeType($format)
13101310
return isset(static::$formats[$format]) ? static::$formats[$format][0] : null;
13111311
}
13121312

1313+
/**
1314+
* Gets the mime types associated with the format.
1315+
*
1316+
* @param string $format The format
1317+
*
1318+
* @return array The associated mime types
1319+
*/
1320+
public static function getMimeTypes($format)
1321+
{
1322+
if (null === static::$formats) {
1323+
static::initializeFormats();
1324+
}
1325+
1326+
return isset(static::$formats[$format]) ? static::$formats[$format] : array();
1327+
}
1328+
13131329
/**
13141330
* Gets the format associated with the mime type.
13151331
*

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,23 @@ public function testGetMimeTypeFromFormat($format, $mimeTypes)
330330
}
331331
}
332332

333+
/**
334+
* @dataProvider getFormatToMimeTypeMapProvider
335+
*/
336+
public function testGetMimeTypesFromFormat($format, $mimeTypes)
337+
{
338+
if (null !== $format) {
339+
$this->assertEquals($mimeTypes, Request::getMimeTypes($format));
340+
}
341+
}
342+
343+
public function testGetMimeTypesFromInexistentFormat()
344+
{
345+
$request = new Request();
346+
$this->assertNull($request->getMimeType('foo'));
347+
$this->assertEquals(array(), Request::getMimeTypes('foo'));
348+
}
349+
333350
public function getFormatToMimeTypeMapProvider()
334351
{
335352
return array(

0 commit comments

Comments
 (0)
0