[CORE][Controller] Define html format as default

This commit is contained in:
Diogo Peralta Cordeiro 2021-12-19 21:05:39 +00:00
parent 1832397363
commit 23f94ac961
No known key found for this signature in database
GPG Key ID: 18D2D35001FBFAB0

View File

@ -142,7 +142,7 @@ abstract class Controller extends AbstractController implements EventSubscriberI
// Respond in the most preferred acceptable content type // Respond in the most preferred acceptable content type
$route = $request->get('_route'); $route = $request->get('_route');
$accept = $request->getAcceptableContentTypes() ?: ['text/html']; $accept = $request->getAcceptableContentTypes() ?: ['text/html']; // Assume html if not specified, */* is considered specified
$format = $request->getFormat($accept[0]); $format = $request->getFormat($accept[0]);
$potential_response = null; $potential_response = null;
if (Event::handle('ControllerResponseInFormat', [ if (Event::handle('ControllerResponseInFormat', [
@ -155,7 +155,7 @@ abstract class Controller extends AbstractController implements EventSubscriberI
case 'json': case 'json':
$event->setResponse(new JsonResponse($response)); $event->setResponse(new JsonResponse($response));
break; break;
case 'html': default: // html (assume if not specified)
if ($template !== null) { if ($template !== null) {
$event->setResponse($this->render($template, $this->vars)); $event->setResponse($this->render($template, $this->vars));
@ -170,12 +170,9 @@ abstract class Controller extends AbstractController implements EventSubscriberI
break; break;
} else { } else {
// no break, goto default
}
// no break
default:
throw new ClientException(_m('Unsupported format: {format}', ['format' => $format]), 406); // 406 Not Acceptable throw new ClientException(_m('Unsupported format: {format}', ['format' => $format]), 406); // 406 Not Acceptable
} }
}
} else { } else {
if (\is_null($potential_response)) { if (\is_null($potential_response)) {
// TODO BugFoundException // TODO BugFoundException