// \Symfony\Component\Routing\Exception\ResourceNotFoundException here
// because we don't want to return a 404 status code, but rather a 406.
$available_formats =
static::
getAvailableFormats($collection);
$not_acceptable =
new NotAcceptableHttpException("No route found for the specified format
$format. Supported formats: " .
implode(', ',
$available_formats) . '.'
);
if ($available_formats) { $links =
[];
foreach ($available_formats as $available_format) { $url = Url::
fromUri($request->
getUri(),
['query' =>
['_format' =>
$available_format]])->
toString(TRUE
)->
getGeneratedUrl();
$content_type =
$request->
getMimeType($available_format);
$links[] = "<
$url>; rel=\"alternate\"; type=\"
$content_type\"";
} $not_acceptable->
setHeaders(['Link' =>
implode(', ',
$links)]);
} throw $not_acceptable;
} /**
* Determines the default request format.
*
* By default, use 'html' as the default format. But when there's only a
* single route match, and that route specifies a '_format' requirement
* listing a single format, then use that as the default format. Also, if
* there are multiple routes which all require the same single format then
* use it.
*
* @param \Symfony\Component\Routing\RouteCollection $collection
* The route collection to filter.
*
* @return string
* The default format.
*/