Abstract Class Yiisoft\DataResponse\Middleware\AbstractDataResponseMiddleware
Abstract middleware class that applies a formatter to {@see DataStream} responses and sets appropriate response headers.
The middleware only formats responses whose body is a {@see \
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| process() | Yiisoft\ |
Method Details
| public mixed __construct ( Yiisoft\ | ||
| $formatter | Yiisoft\ |
The formatter to apply to the response. |
public function __construct(
private readonly FormatterInterface $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.