From 4618c9f9f812e5b4034cfd6ab9031800fb47fc6c Mon Sep 17 00:00:00 2001 From: Ener-Getick Date: Fri, 8 Jan 2016 22:17:51 +0100 Subject: [PATCH] [HttpFoundation] Allow to get all the mime types associated to a format in the Request --- .../Component/HttpFoundation/Request.php | 16 ++++++++++++++++ .../HttpFoundation/Tests/RequestTest.php | 17 +++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 77f3d15f0024d..63d25918913ff 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -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. * diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index 70bc15bce6fca..365c9d3cec00f 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -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(