Interface Yiisoft\DataResponse\Formatter\FormatterInterface
Interface that should be implemented by data formatters.
Data formatters are responsible for converting data into a specific format (e.g., JSON, XML, HTML) and applying the formatted content to HTTP responses.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| formatData() | Formats the given data into a stream or string representation. | Yiisoft\ |
| formatResponse() | Applies the formatter's headers to the response. | Yiisoft\ |
Method Details
Formats the given data into a stream or string representation.
| public abstract \ | ||
| $data | mixed |
The data to be formatted. |
| return | \ |
The formatted data as a stream or string. |
|---|---|---|
| throws | Yiisoft\ |
If the data cannot be encoded into the target format. |
public function formatData(mixed $data): StreamInterface|string;
Applies the formatter's headers to the response.
This method does not format the response body data. Use {@see \
| public abstract \ | ||
| $response | \ |
The response to apply headers to. |
| return | \ |
The response with the applied headers. |
|---|---|---|
public function formatResponse(ResponseInterface $response): ResponseInterface;
User Contributed Notes
Leave a comment
Join the conversation to share a note.