Final Class Yiisoft\DataResponse\Formatter\HtmlDataResponseFormatter
| Inheritance | Yiisoft\DataResponse\Formatter\HtmlDataResponseFormatter |
|---|---|
| Implements | Yiisoft\DataResponse\DataResponseFormatterInterface |
| Uses Traits | Yiisoft\DataResponse\ResponseContentTrait |
HtmlDataResponseFormatter formats the response data as HTML.
Public 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
| 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);
}
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;
}
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;
}
Signup or Login in order to comment.