0 follower

Final Class Yiisoft\DataResponse\Formatter\HtmlDataResponseFormatter

InheritanceYiisoft\DataResponse\Formatter\HtmlDataResponseFormatter
ImplementsYiisoft\DataResponse\DataResponseFormatterInterface
Uses TraitsYiisoft\DataResponse\ResponseContentTrait

HtmlDataResponseFormatter formats the response data as HTML.

Public Methods

Hide inherited methods

Method Description Defined By
format() Yiisoft\DataResponse\Formatter\HtmlDataResponseFormatter
withContentType() Returns a new instance with the specified content type. Yiisoft\DataResponse\ResponseContentTrait
withEncoding() Returns a new instance with the specified encoding. Yiisoft\DataResponse\ResponseContentTrait

Method Details

Hide inherited methods

format() public method

public \Psr\Http\Message\ResponseInterface format ( Yiisoft\DataResponse\DataResponse $dataResponse )
$dataResponse Yiisoft\DataResponse\DataResponse

                public function format(DataResponse $dataResponse): ResponseInterface
{
    $data = $dataResponse->getData();
    if (!is_scalar($data) && $data !== null && !$data instanceof Stringable) {
        throw new RuntimeException(
            sprintf(
                'Data must be either a scalar value, null, or a stringable object. %s given.',
                get_debug_type($data),
            )
        );
    }
    return $this->addToResponse($dataResponse->getResponse(), empty($data) ? null : (string) $data);
}

            
withContentType() public method

Defined in: Yiisoft\DataResponse\ResponseContentTrait::withContentType()

Returns a new instance with the specified content type.

public self withContentType ( string $contentType )
$contentType string

The content type. For example, "text/html".

                public function withContentType(string $contentType): self
{
    $new = clone $this;
    $new->contentType = $contentType;
    return $new;
}

            
withEncoding() public method

Defined in: Yiisoft\DataResponse\ResponseContentTrait::withEncoding()

Returns a new instance with the specified encoding.

public self withEncoding ( string $encoding )
$encoding string

The encoding. For example, "UTF-8".

                public function withEncoding(string $encoding): self
{
    $new = clone $this;
    $new->encoding = $encoding;
    return $new;
}