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\DataResponse\Formatter\FormatterInterface |
| formatResponse() | Applies the formatter's headers to the response. | Yiisoft\DataResponse\Formatter\FormatterInterface |
Method Details
Formats the given data into a stream or string representation.
| public abstract formatData( mixed $data ): \Psr\Http\Message\StreamInterface|string | ||
| $data | mixed |
The data to be formatted. |
| return | \Psr\Http\Message\StreamInterface|string |
The formatted data as a stream or string. |
|---|---|---|
| throws | Yiisoft\DataResponse\Formatter\DataEncodingException |
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 formatData() to format the data.
| public abstract formatResponse( \Psr\Http\Message\ResponseInterface $response ): \Psr\Http\Message\ResponseInterface | ||
| $response | \Psr\Http\Message\ResponseInterface |
The response to apply headers to. |
| return | \Psr\Http\Message\ResponseInterface |
The response with the applied headers. |
|---|---|---|
public function formatResponse(ResponseInterface $response): ResponseInterface;
Signup or Login in order to comment.