class ContentNegociator (View source)

Traits

SingletonTrait

Constants

STRICT

String mode negociation flags.

Always honor the Accept[-*] header and raise ContentNegociationException even if the receommanded behavior is to ignore the header on negociation failure.

Applies to

  • Language negociation
  • Charset negotiation

ALL_MATCH

Negociation flag.

Negociation methods will return an array containing all available entries that fullfil the Accept[-*] header conditions instead of returning the best match only.

Methods

array
negociate(RequestInterface $request, $availables = array(), $flags = 0)

No description

ResponseInterface
populateResponse(ResponseInterface $response, array $negociatied, array $availables = null)

No description

MediaTypeInterface
negociateContentType($accepted, $available, $flags = 0)

No description

string|mixed|array|unknown[]|Iterator[]|mixed[]|NULL[]|array[]|ArrayAccess[]|ContainerInterface[]|Traversable[]
negociateEncoding($accepted, $available, $flags = 0)

No description

negociateCharset($accepted, $available, $flags = 0)

No description

mixed
negociateLanguage($accepted, $available, $flags = 0)

No description

number
getContentTypeQualityValue(MediaTypeInterface $contentType, Traversable $acceptedMediaRanges)

Compute the quality value of the given media type against a list of accepted media ranges.

MediaTypeInterface
normalizeMediaType(mixed $input)

No description

appendCharset($entry, $charset)

No description

Details

array negociate(RequestInterface $request, $availables = array(), $flags = 0)

Parameters

RequestInterface $request
$availables
$flags

Return Value

array mixed>

ResponseInterface populateResponse(ResponseInterface $response, array $negociatied, array $availables = null)

Parameters

ResponseInterface $response The response to alter
array $negociatied Result of negociation
array $availables Same list of available alternative given during negociation. List of header name is also accepted.

Return Value

ResponseInterface A new response, copy of the response given in parameter filled with negociation headers.

MediaTypeInterface negociateContentType($accepted, $available, $flags = 0)

Parameters

$accepted
$available
$flags

Return Value

MediaTypeInterface

string|mixed|array|unknown[]|Iterator[]|mixed[]|NULL[]|array[]|ArrayAccess[]|ContainerInterface[]|Traversable[] negociateEncoding($accepted, $available, $flags = 0)

Parameters

$accepted
$available
$flags

Return Value

string|mixed|array|unknown[]|Iterator[]|mixed[]|NULL[]|array[]|ArrayAccess[]|ContainerInterface[]|Traversable[]

See also

https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.4

negociateCharset($accepted, $available, $flags = 0)

Parameters

$accepted
$available
$flags

mixed negociateLanguage($accepted, $available, $flags = 0)

Parameters

$accepted
$available
$flags

Return Value

mixed

Exceptions

ContentNegociationException

number getContentTypeQualityValue(MediaTypeInterface $contentType, Traversable $acceptedMediaRanges)

Compute the quality value of the given media type against a list of accepted media ranges.

Parameters

MediaTypeInterface $contentType
Traversable $acceptedMediaRanges List of AcceptHeaderValue or MediaRange with quality value parameter.

Return Value

number Quality value in the range [0.001, 1] or -1 if media type is not acceptable

protected MediaTypeInterface normalizeMediaType(mixed $input)

Parameters

mixed $input

Return Value

MediaTypeInterface

protected appendCharset($entry, $charset)

Parameters

$entry
$charset