private function getFormat(Request $request) : string
{
$contentType = $request->headers->get('CONTENT_TYPE');
if (null === $contentType) {
throw new NotAcceptableHttpException('The "Content-Type" header must exist.');
}
$format = $request->getFormat($contentType);
if (!isset($this->formats[$format])) {
$supportedMimeTypes = [];
foreach ($this->formats as $mimeTypes) {
foreach ($mimeTypes as $mimeType) {
$supportedMimeTypes[] = $mimeType;
}
}
throw new NotAcceptableHttpException(sprintf('The content-type "%s" is not supported. Supported MIME types are "%s".', $contentType, implode('", "', $supportedMimeTypes)));
}
return $format;
}