0 follower

Final Class Yiisoft\DataResponse\Middleware\FormatDataResponseAsPlainText

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

FormatDataResponseAsPlainText adds a plain text formatter {@see PlainTextDataResponseFormatter} 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\PlainTextDataResponseFormatter $responseFormatter )
$responseFormatter Yiisoft\DataResponse\Formatter\PlainTextDataResponseFormatter

                public function __construct(PlainTextDataResponseFormatter $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;
}