0 follower

Final Class Yiisoft\DataResponse\Middleware\HtmlDataResponseMiddleware

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

Middleware that formats {@see DataStream} responses as HTML and sets appropriate response headers.

Method Details

Hide inherited methods

__construct() public method

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

The HTML formatter to use.

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

            
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

                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);
}