Negotiates the prefered content type from what the application provides and what the request has in its Accept header.
Check if the request accepts a given language code.
Get the normalized list of accepted languages
Parse Accept* headers with qualifier options.
Parse the Accept-Language header
Parse a header value into preference => value mapping
Get the most preferred content type from a request.
acceptLanguage(Psr\Http\Message\RequestInterface $request, string $lang): bool
Check if the request accepts a given language code.
Language codes in the request will be normalized to lower case and have _ replaced with -.
Psr\Http\Message\RequestInterface $request The request to read headers from.
string $lang The language code to check.
boolacceptedLanguages(Psr\Http\Message\RequestInterface $request): array<string>
Get the normalized list of accepted languages
Language codes in the request will be normalized to lower case and have _ replaced with -.
Psr\Http\Message\RequestInterface $request The request to read headers from.
array<string>parseAccept(Psr\Http\Message\RequestInterface $request): array<string, array<string>>
Parse Accept* headers with qualifier options.
Only qualifiers will be extracted, any other accept extensions will be discarded as they are not frequently used.
Psr\Http\Message\RequestInterface $request The request to get an accept from.
array<string, array<string>>parseAcceptLanguage(Psr\Http\Message\RequestInterface $request): array<string, array<string>>
Parse the Accept-Language header
Only qualifiers will be extracted, other extensions will be ignored as they are not frequently used.
Psr\Http\Message\RequestInterface $request The request to get an accept from.
array<string, array<string>>parseQualifiers(string $header): array<string, array<string>>
Parse a header value into preference => value mapping
string $header The header value to parse
array<string, array<string>>preferredType(Psr\Http\Message\RequestInterface $request, array<string> $choices = []): string|null
Get the most preferred content type from a request.
Parse the Accept header preferences and return the most preferred type. If multiple types are tied in preference the first type of that preference value will be returned.
You can expect null when the request has no Accept header.
Psr\Http\Message\RequestInterface $request The request to use.
array<string> $choices optional The supported content type choices.
string|null
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.4/class-Cake.Http.ContentTypeNegotiation.html