CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 4.6 Strawberry API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 4.6
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • Http
      • Client
      • Cookie
      • Exception
      • Middleware
      • Session
      • TestSuite
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View

Class ContentTypeNegotiation

Negotiates the prefered content type from what the application provides and what the request has in its Accept header.

Namespace: Cake\Http

Method Summary

  • acceptLanguage() public

    Check if the request accepts a given language code.

  • acceptedLanguages() public

    Get the normalized list of accepted languages

  • parseAccept() public

    Parse Accept* headers with qualifier options.

  • parseAcceptLanguage() public

    Parse the Accept-Language header

  • parseQualifiers() protected

    Parse a header value into preference => value mapping

  • preferredType() public

    Get the most preferred content type from a request.

Method Detail

acceptLanguage() ¶ public

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 -.

Parameters
Psr\Http\Message\RequestInterface $request

The request to read headers from.

string $lang

The language code to check.

Returns
bool

acceptedLanguages() ¶ public

acceptedLanguages(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 -.

Parameters
Psr\Http\Message\RequestInterface $request

The request to read headers from.

Returns
array<string>

parseAccept() ¶ public

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.

Parameters
Psr\Http\Message\RequestInterface $request

The request to get an accept from.

Returns
array<string, array<string>>

parseAcceptLanguage() ¶ public

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.

Parameters
Psr\Http\Message\RequestInterface $request

The request to get an accept from.

Returns
array<string, array<string>>

parseQualifiers() ¶ protected

parseQualifiers(string $header): array<string, array<string>>

Parse a header value into preference => value mapping

Parameters
string $header

The header value to parse

Returns
array<string, array<string>>

preferredType() ¶ public

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.

Parameters
Psr\Http\Message\RequestInterface $request

The request to use.

array<string> $choices optional

The supported content type choices.

Returns
string|null
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs