0 follower

Final Class Yiisoft\DataResponse\ResponseFactory\DataResponseFactory

InheritanceYiisoft\DataResponse\ResponseFactory\DataResponseFactory
ImplementsYiisoft\DataResponse\ResponseFactory\DataResponseFactoryInterface

Factory that creates responses with {@see DataStream} body without applying a formatter.

The formatter should be applied later using middleware.

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( \Psr\Http\Message\ResponseFactoryInterface $responseFactory )
$responseFactory \Psr\Http\Message\ResponseFactoryInterface

The PSR-17 response factory.

                public function __construct(
    private readonly ResponseFactoryInterface $responseFactory,
) {}

            
createResponse() public method

public \Psr\Http\Message\ResponseInterface createResponse ( mixed $data null, integer $code Status::OK, string $reasonPhrase '' )
$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);
}