$parsers
$parsers : array
Registered Parsers
Parse encoded request body data.
Enables JSON and XML request payloads to be parsed into the request's Provides CSRF protection & validation.
You can also add your own request body parsers using the addParser()
method.
__construct(array $options = array())
Constructor
json
Set to false to disable json body parsing.xml
Set to true to enable XML parsing. Defaults to false, as XML
handling requires more care than JSON does.methods
The HTTP methods to parse on. Defaults to PUT, POST, PATCH DELETE.array | $options | The options to use. See above. |
addParser(array $types, callable $parser) : $this
Add a parser.
Map a set of content-type header values to be parsed by the $parser.
An naive CSV request body parser could be built like so:
$parser->addParser(['text/csv'], function ($body) {
return str_getcsv($body);
});
array | $types | An array of content-type header values to match. eg. application/json |
callable | $parser | The parser function. Must return an array of data to be inserted into the request. |
__invoke(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, callable $next) : \Cake\Http\Response
Apply the middleware.
Will modify the request adding a parsed body if the content-type is known.
\Psr\Http\Message\ServerRequestInterface | $request | The request. |
\Psr\Http\Message\ResponseInterface | $response | The response. |
callable | $next | Callback to invoke the next middleware. |
A response
Loading…