class HtmlResponse extends Response implements CacheableResponseInterface, AttachmentsInterface (View source)

Response that contains and can expose cacheability metadata and attachments.

Supports Drupal's caching concepts: cache tags for invalidation and cache contexts for variations.

Supports Drupal's idea of #attached metadata: libraries, settings, http_header and html_head.

Traits

Provides an implementation of CacheableResponseInterface.

Provides an implementation of AttachmentsInterface.

Properties

protected CacheableMetadata $cacheabilityMetadata

The cacheability metadata.

from  CacheableResponseTrait
protected array $attachments

The attachments for this response.

from  AttachmentsTrait

Methods

addCacheableDependency($dependency)

{@inheritdoc}

getAttachments()

{@inheritdoc}

addAttachments(array $attachments)

{@inheritdoc}

setAttachments(array $attachments)

{@inheritdoc}

__construct(array|string $content = '', int $status = 200, array $headers = [])

Constructs a HtmlResponse object.

$this
setContent(mixed $content)

Sets the response content.

Details

addCacheableDependency($dependency)

{@inheritdoc}

Parameters

$dependency

getCacheableMetadata()

{@inheritdoc}

getAttachments()

{@inheritdoc}

addAttachments(array $attachments)

{@inheritdoc}

Parameters

array $attachments

setAttachments(array $attachments)

{@inheritdoc}

Parameters

array $attachments

__construct(array|string $content = '', int $status = 200, array $headers = [])

Constructs a HtmlResponse object.

Parameters

array|string $content

The response content, see setContent().

int $status

The response status code.

array $headers

An array of response headers.

Exceptions

InvalidArgumentException

$this setContent(mixed $content)

Sets the response content.

Parameters

mixed $content

Content that can be cast to string, or a render array.

Return Value

$this