class NegotiationMiddleware implements HttpKernelInterface (View source)

Provides a middleware to determine the content type upon the accept header.

Properties

protected HttpKernelInterface $app

The wrapped HTTP kernel.

protected array $formats

Contains a hashmap of format as key and mimetype as value.

Methods

__construct(HttpKernelInterface $app)

Constructs a new NegotiationMiddleware.

Response
handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE)

{@inheritdoc}

$this
registerFormat(string $format, string $mime_type)

Registers a format for a given MIME type.

string
getContentType(Request $request)

Gets the normalized type of a request.

Details

__construct(HttpKernelInterface $app)

Constructs a new NegotiationMiddleware.

Parameters

HttpKernelInterface $app

The wrapper HTTP kernel

Response handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE)

{@inheritdoc}

Parameters

Request $request
$type
$catch

Return Value

Response

$this registerFormat(string $format, string $mime_type)

Registers a format for a given MIME type.

Parameters

string $format

The format.

string $mime_type

The MIME type.

Return Value

$this

protected string getContentType(Request $request)

Gets the normalized type of a request.

The normalized type is a short, lowercase version of the format, such as 'html', 'json' or 'atom'.

Parameters

Request $request

The request object from which to extract the content type.

Return Value

string

The normalized type of a given request.