0 follower

Final Class Yiisoft\DataResponse\ResponseFactory\DataResponseFactory

InheritanceYiisoft\DataResponse\ResponseFactory\DataResponseFactory
ImplementsYiisoft\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.

Method Details

Hide inherited methods

__construct() public method

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,
) {}

            
createResponse() public method

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);
}