0 follower

Final Class Yiisoft\DataResponse\Middleware\PlainTextDataResponseMiddleware

InheritanceYiisoft\DataResponse\Middleware\PlainTextDataResponseMiddleware » Yiisoft\DataResponse\Middleware\AbstractDataResponseMiddleware
ImplementsPsr\Http\Server\MiddlewareInterface

Middleware that formats Yiisoft\DataResponse\DataStream\DataStream responses as plain text and sets appropriate response headers.

Method Details

Hide inherited methods

__construct() public method

public __construct( Yiisoft\DataResponse\Formatter\PlainTextFormatter $formatter = new PlainTextFormatter() ): mixed
$formatter Yiisoft\DataResponse\Formatter\PlainTextFormatter

The plain text formatter to use.

                public function __construct(PlainTextFormatter $formatter = new PlainTextFormatter())
{
    parent::__construct($formatter);
}

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

                final public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
    $response = $handler->handle($request);
    $body = $response->getBody();
    if (!$body instanceof DataStream || $body->hasFormatter()) {
        return $response;
    }
    $body->changeFormatter($this->formatter);
    return $this->formatter->formatResponse($response);
}