PayloadParsingMiddleware
Unified body parsing leveraging middlewares/payload.
Responsibilities: - Parse JSON (application/json, +json types) strict by default; 400 on invalid unless QUIOTE_JSON_STRICT=0 - Parse application/x-www-form-urlencoded (if not already parsed) - Skip re-parsing if the parsed body is already set (e.g. by an earlier middleware) Order: should run before routing and after tracing.
Synopsis
Section titled “Synopsis”class PayloadParsingMiddleware implements MiddlewareInterface
| Implements | MiddlewareInterface |
| Source | Middleware/PayloadParsingMiddleware.php |
Constructor
Section titled “Constructor”__construct()
Section titled “__construct()”public function __construct(?bool $strict = null, EnvironmentReaderInterface $environment = new SystemEnvironmentReader(…)): mixed
| Parameter | Type | Description |
|---|---|---|
$strict | ?``bool | |
$environment | EnvironmentReaderInterface |
Returns mixed
Methods
Section titled “Methods”| Method | Description |
|---|---|
process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | Parses the request body into the parsed-body slot before routing runs. |
process()
Section titled “process()”public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
Parses the request body into the parsed-body slot before routing runs.
A request that already has a parsed body is passed straight through, so an earlier middleware’s or a test’s parsing is never overwritten. A application/x-www-form-urlencoded body is parsed with parse_str(); anything else is handed to the JsonPayload middleware, which only acts on JSON content types.
Malformed JSON produces a 400 with an invalid_json JSON body when strict mode is on — the default, overridable by the constructor or by setting QUIOTE_JSON_STRICT=0 — and otherwise falls through with the body left unparsed. Any other throwable is rethrown so ErrorHandlingMiddleware formats it.
| Parameter | Type | Description |
|---|---|---|
$request | ServerRequestInterface | |
$handler | RequestHandlerInterface |
Returns ResponseInterface