Final Class Yiisoft\DataResponse\Formatter\HtmlDataResponseFormatter
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
| Uses Traits | Yiisoft\ |
| Deprecated since version | Use {@see \ |
HtmlDataResponseFormatter formats the response data as HTML.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| format() | Yiisoft\ |
|
| withContentType() | Returns a new instance with the specified content type. | Yiisoft\ |
| withEncoding() | Returns a new instance with the specified encoding. | Yiisoft\ |
Method Details
| public \ | ||
| $dataResponse | Yiisoft\ |
|
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\
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\
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;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.