Skip to content

FormPopulationMiddleware

Applies the modernized form population engine to PSR-7 responses so container-less requests still receive automatic form value and error message population.

class FormPopulationMiddleware implements MiddlewareInterface

ImplementsMiddlewareInterface
SourceMiddleware/FormPopulationMiddleware.php

public function __construct(Controller $controller, ?FormPopulationEngine $engine = null): mixed

ParameterTypeDescription
$controllerController
$engine?FormPopulationEngine

Returns mixed

MethodDescription
process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterfaceRepopulates form fields and error messages in the rendered HTML response.

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface

Repopulates form fields and error messages in the rendered HTML response.

On the way in, the canonical WebRequest is resolved (from the quiote.request_data attribute, else from the container), given the merged query, parsed-body and route parameters — later sources winning on key conflicts — seeded with the engine’s default configuration, then published to RequestState and re-attached to the request.

On the way out the response is returned untouched unless every gate passes: the Content-Type must look like HTML (a missing Content-Type is treated as HTML), the body must be non-empty, the controller’s global response must still allow content mutation, and the body must actually contain a <form — the last check skips the DOM round-trip for the common form-free page. When population does run and changes the markup, a new body is installed and any stale Content-Length header is removed. The engine is reset even if population throws.

ParameterTypeDescription
$requestServerRequestInterface
$handlerRequestHandlerInterface

Returns ResponseInterface

ThrowsWhen
RuntimeExceptionIf no canonical WebRequest can be resolved.