0 follower

Class Yiisoft\DataResponse\Middleware\FormatDataResponse

InheritanceYiisoft\DataResponse\Middleware\FormatDataResponse
ImplementsPsr\Http\Server\MiddlewareInterface
SubclassesYiisoft\DataResponse\Middleware\FormatDataResponseAsHtml, Yiisoft\DataResponse\Middleware\FormatDataResponseAsJson, Yiisoft\DataResponse\Middleware\FormatDataResponseAsPlainText, Yiisoft\DataResponse\Middleware\FormatDataResponseAsXml

FormatDataResponse adds a formatter {@see DataResponseFormatterInterface} instance to the instance of the data response {@see DataResponse}, if the formatter was not added earlier.

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( Yiisoft\DataResponse\DataResponseFormatterInterface $responseFormatter )
$responseFormatter Yiisoft\DataResponse\DataResponseFormatterInterface

                public function __construct(
    private DataResponseFormatterInterface $responseFormatter,
) {
}

            
process() public method

public \Psr\Http\Message\ResponseInterface process ( \Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Server\RequestHandlerInterface $handler )
$request \Psr\Http\Message\ServerRequestInterface
$handler \Psr\Http\Server\RequestHandlerInterface

                public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
    $response = $handler->handle($request);
    if ($response instanceof DataResponse && !$response->hasResponseFormatter()) {
        $response = $response->withResponseFormatter($this->responseFormatter);
    }
    return $response;
}