[Request] Fix support of custom mime types with parameters
This commit is contained in:
parent
483da73079
commit
f7ad285746
@ -1238,8 +1238,9 @@ class Request
|
||||
*/
|
||||
public function getFormat($mimeType)
|
||||
{
|
||||
$canonicalMimeType = null;
|
||||
if (false !== $pos = strpos($mimeType, ';')) {
|
||||
$mimeType = substr($mimeType, 0, $pos);
|
||||
$canonicalMimeType = substr($mimeType, 0, $pos);
|
||||
}
|
||||
|
||||
if (null === static::$formats) {
|
||||
@ -1250,6 +1251,9 @@ class Request
|
||||
if (in_array($mimeType, (array) $mimeTypes)) {
|
||||
return $format;
|
||||
}
|
||||
if (null !== $canonicalMimeType && in_array($canonicalMimeType, (array) $mimeTypes)) {
|
||||
return $format;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
{
|
||||
return array(
|
||||
|
Reference in New Issue
Block a user