Skip to content

OutputTypeSyncMiddleware

Synchronizes the Controller’s current output type with the PSR request attribute ‘output_type’ after routing has resolved (and potentially overridden) it.

Ensures downstream code relying on $controller->getOutputType() sees the correct routed/negotiated value.

class OutputTypeSyncMiddleware implements MiddlewareInterface

ImplementsMiddlewareInterface
SourceMiddleware/OutputTypeSyncMiddleware.php

public function __construct(Controller $controller): mixed

ParameterTypeDescription
$controllerController

Returns mixed

MethodDescription
process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterfaceSelects the request’s output_type on the Controller.

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

Selects the request’s output_type on the Controller.

Ordered after RoutingMiddleware and before SecurityMiddleware, so the value it applies is the one routing settled on rather than the raw negotiated one. Nothing happens when the attribute is absent or empty. A name the application does not define is logged at debug and otherwise ignored, leaving the controller’s current selection in place.

ParameterTypeDescription
$requestServerRequestInterface
$handlerRequestHandlerInterface

Returns ResponseInterface