0 follower

Interface Yiisoft\DataResponse\Formatter\FormatterInterface

Implemented byYiisoft\DataResponse\Formatter\HtmlFormatter, Yiisoft\DataResponse\Formatter\JsonFormatter, Yiisoft\DataResponse\Formatter\PlainTextFormatter, Yiisoft\DataResponse\Formatter\XmlFormatter

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

Hide inherited 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

Hide inherited methods

formatData() public abstract method

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;

            
formatResponse() public abstract method

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;