[Request] Fix support of custom mime types with parameters

This commit is contained in:
Ener-Getick 2016-03-21 20:54:26 +01:00
parent 483da73079
commit f7ad285746
2 changed files with 12 additions and 1 deletions

View File

@ -1238,8 +1238,9 @@ class Request
*/ */
public function getFormat($mimeType) public function getFormat($mimeType)
{ {
$canonicalMimeType = null;
if (false !== $pos = strpos($mimeType, ';')) { if (false !== $pos = strpos($mimeType, ';')) {
$mimeType = substr($mimeType, 0, $pos); $canonicalMimeType = substr($mimeType, 0, $pos);
} }
if (null === static::$formats) { if (null === static::$formats) {
@ -1250,6 +1251,9 @@ class Request
if (in_array($mimeType, (array) $mimeTypes)) { if (in_array($mimeType, (array) $mimeTypes)) {
return $format; return $format;
} }
if (null !== $canonicalMimeType && in_array($canonicalMimeType, (array) $mimeTypes)) {
return $format;
}
} }
} }

View File

@ -325,6 +325,13 @@ class RequestTest extends \PHPUnit_Framework_TestCase
} }
} }
public function testGetFormatWithCustomMimeType()
{
$request = new Request();
$request->setFormat('custom', 'application/vnd.foo.api;myversion=2.3');
$this->assertEquals('custom', $request->getFormat('application/vnd.foo.api;myversion=2.3'));
}
public function getFormatToMimeTypeMapProvider() public function getFormatToMimeTypeMapProvider()
{ {
return array( return array(