Final Class Yiisoft\DataResponse\Middleware\HtmlDataResponseMiddleware
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Psr\ |
Middleware that formats {@see DataStream} responses as HTML and sets appropriate response headers.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| process() | Yiisoft\ |
Method Details
| public mixed __construct ( Yiisoft\ | ||
| $formatter | Yiisoft\ |
The HTML formatter to use. |
public function __construct(HtmlFormatter $formatter = new HtmlFormatter())
{
parent::__construct($formatter);
}
| public \ | ||
| $request | \ |
|
| $handler | \ |
|
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);
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.