0 follower

Final Class Yiisoft\DataResponse\Middleware\FormatDataResponseAsJson

InheritanceYiisoft\DataResponse\Middleware\FormatDataResponseAsJson » Yiisoft\DataResponse\Middleware\FormatDataResponse
ImplementsPsr\Http\Server\MiddlewareInterface

FormatDataResponseAsJson adds a JSON formatter {@see JsonDataResponseFormatter} 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\Formatter\JsonDataResponseFormatter $responseFormatter )
$responseFormatter Yiisoft\DataResponse\Formatter\JsonDataResponseFormatter

                public function __construct(JsonDataResponseFormatter $responseFormatter)
{
    parent::__construct($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;
}