Final Class Yiisoft\DataResponse\ResponseFactory\DataResponseFactory
| Inheritance | Yiisoft\DataResponse\ResponseFactory\DataResponseFactory |
|---|---|
| Implements | Yiisoft\DataResponse\ResponseFactory\DataResponseFactoryInterface |
Factory that creates responses with Yiisoft\DataResponse\DataStream\DataStream body without applying a formatter.
The formatter should be applied later using middleware.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\DataResponse\ResponseFactory\DataResponseFactory | |
| createResponse() | Yiisoft\DataResponse\ResponseFactory\DataResponseFactory |
Method Details
| public __construct( \Psr\Http\Message\ResponseFactoryInterface $responseFactory ): mixed | ||
| $responseFactory | \Psr\Http\Message\ResponseFactoryInterface |
The PSR-17 response factory. |
public function __construct(
private readonly ResponseFactoryInterface $responseFactory,
) {}
| public createResponse( mixed $data = null, integer $code = Status::OK, string $reasonPhrase = '' ): \Psr\Http\Message\ResponseInterface | ||
| $data | mixed | |
| $code | integer | |
| $reasonPhrase | string | |
public function createResponse(
mixed $data = null,
int $code = Status::OK,
string $reasonPhrase = '',
): ResponseInterface {
$body = new DataStream($data);
return $this->responseFactory
->createResponse($code, $reasonPhrase)
->withBody($body);
}
Signup or Login in order to comment.