0 follower

Final Class Yiisoft\DataResponse\ResponseFactory\PlainTextResponseFactory

InheritanceYiisoft\DataResponse\ResponseFactory\PlainTextResponseFactory » Yiisoft\DataResponse\ResponseFactory\AbstractFormattedResponseFactory
ImplementsYiisoft\DataResponse\ResponseFactory\DataResponseFactoryInterface

Factory that creates responses with plain text formatted Yiisoft\DataResponse\DataStream\DataStream body and appropriate response headers.

Method Details

Hide inherited methods

__construct() public method

public __construct( \Psr\Http\Message\ResponseFactoryInterface $responseFactory, Yiisoft\DataResponse\Formatter\PlainTextFormatter $formatter ): mixed
$responseFactory \Psr\Http\Message\ResponseFactoryInterface

The PSR-17 response factory.

$formatter Yiisoft\DataResponse\Formatter\PlainTextFormatter

The plain text formatter to use.

                public function __construct(
    ResponseFactoryInterface $responseFactory,
    PlainTextFormatter $formatter,
) {
    parent::__construct($responseFactory, $formatter);
}

            
createResponse() public method
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);
}