public getNegotiatedMediaType ( array $supportedMediaTypes, boolean $trim = true ) : string | ||
$supportedMediaTypes | array | A list of media types which are supported by the application / controller |
$trim | boolean | If TRUE, only the type/subtype of the media type is returned. If FALSE, the full original media type string is returned. |
return | string | The media type and sub type which matched, NULL if none matched |
public function getNegotiatedMediaType(array $supportedMediaTypes, $trim = true)
{
$negotiatedMediaType = null;
$acceptedMediaTypes = $this->getAcceptedMediaTypes();
foreach ($acceptedMediaTypes as $acceptedMediaType) {
foreach ($supportedMediaTypes as $supportedMediaType) {
if (MediaTypes::mediaRangeMatches($acceptedMediaType, $supportedMediaType)) {
$negotiatedMediaType = $supportedMediaType;
break 2;
}
}
}
return $trim ? MediaTypes::trimMediaType($negotiatedMediaType) : $negotiatedMediaType;
}