Final Class Yiisoft\DataResponse\ResponseFactory\FormattedResponseFactory
Factory that creates responses with a custom formatter applied to the Yiisoft\DataResponse\DataStream\DataStream body and appropriate response headers.
Public Methods
Method Details
| public __construct( \Psr\Http\Message\ResponseFactoryInterface $responseFactory, Yiisoft\DataResponse\Formatter\FormatterInterface $formatter ): mixed | ||
| $responseFactory | \Psr\Http\Message\ResponseFactoryInterface |
The PSR-17 response factory. |
| $formatter | Yiisoft\DataResponse\Formatter\FormatterInterface |
The formatter to apply to the response. |
public function __construct(
private readonly ResponseFactoryInterface $responseFactory,
private readonly FormatterInterface $formatter,
) {}
| public createResponse( mixed $data = null, integer $code = Status::OK, string $reasonPhrase = '' ): \Psr\Http\Message\ResponseInterface | ||
| $data | mixed | |
| $code | integer | |
| $reasonPhrase | string | |
final public function createResponse(
mixed $data = null,
int $code = Status::OK,
string $reasonPhrase = '',
): ResponseInterface {
$body = new DataStream($data, $this->formatter);
$response = $this->responseFactory
->createResponse($code, $reasonPhrase)
->withBody($body);
return $this->formatter->formatResponse($response);
}
Signup or Login in order to comment.