function Request::getPreferredFormat
Gets the preferred format for the response by inspecting, in the following order:
- the request format set using setRequestFormat;
- the values of the Accept HTTP header.
Note that if you use this method, you should send the "Vary: Accept" header in the response to prevent any issues with intermediary HTTP caches.
File
-
vendor/
symfony/ http-foundation/ Request.php, line 1519
Class
- Request
- Request represents an HTTP request.
Namespace
Symfony\Component\HttpFoundationCode
public function getPreferredFormat(?string $default = 'html') : ?string {
if (!isset($this->preferredFormat) && null !== ($preferredFormat = $this->getRequestFormat(null))) {
$this->preferredFormat = $preferredFormat;
}
if ($this->preferredFormat ?? null) {
return $this->preferredFormat;
}
foreach ($this->getAcceptableContentTypes() as $mimeType) {
if ($this->preferredFormat = $this->getFormat($mimeType)) {
return $this->preferredFormat;
}
}
return $default;
}