Skip to content

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.

class PayloadParsingMiddleware implements MiddlewareInterface

ImplementsMiddlewareInterface
SourceMiddleware/PayloadParsingMiddleware.php

public function __construct(?bool $strict = null, EnvironmentReaderInterface $environment = new SystemEnvironmentReader(…)): mixed

ParameterTypeDescription
$strict?``bool
$environmentEnvironmentReaderInterface

Returns mixed

MethodDescription
process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterfaceParses the request body into the parsed-body slot before routing runs.

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.

ParameterTypeDescription
$requestServerRequestInterface
$handlerRequestHandlerInterface

Returns ResponseInterface