Same name in this branch
  1. 10 core/modules/jsonapi/src/ResourceResponse.php \Drupal\jsonapi\ResourceResponse
  2. 10 core/modules/rest/src/ResourceResponse.php \Drupal\rest\ResourceResponse
Same name and namespace in other branches
  1. 8.9.x core/modules/rest/src/ResourceResponse.php \Drupal\rest\ResourceResponse
  2. 9 core/modules/rest/src/ResourceResponse.php \Drupal\rest\ResourceResponse

Contains data for serialization before sending the response.

We do not want to abuse the $content property on the Response class to store our response data. $content implies that the provided data must either be a string or an object with a __toString() method, which is not a requirement for data used here.

Routes that return this response must specify the '_format' requirement.

Hierarchy

Expanded class hierarchy of ResourceResponse

See also

\Drupal\rest\ModifiedResourceResponse

3 files declare their use of ResourceResponse
RequestHandlerTest.php in core/modules/rest/tests/src/Kernel/RequestHandlerTest.php
ResourceResponseSubscriberTest.php in core/modules/rest/tests/src/Unit/EventSubscriber/ResourceResponseSubscriberTest.php
ResourceResponseValidatorTest.php in core/modules/jsonapi/tests/src/Unit/EventSubscriber/ResourceResponseValidatorTest.php

File

core/modules/rest/src/ResourceResponse.php, line 21

Namespace

Drupal\rest
View source
class ResourceResponse extends Response implements CacheableResponseInterface, ResourceResponseInterface {
  use CacheableResponseTrait;
  use ResourceResponseTrait;

  /**
   * Constructor for ResourceResponse objects.
   *
   * @param mixed $data
   *   Response data that should be serialized.
   * @param int $status
   *   The response status code.
   * @param array $headers
   *   An array of response headers.
   */
  public function __construct($data = NULL, $status = 200, $headers = []) {
    $this->responseData = $data;
    parent::__construct('', $status, $headers);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheableResponseTrait::$cacheabilityMetadata protected property The cacheability metadata.
CacheableResponseTrait::addCacheableDependency public function
CacheableResponseTrait::getCacheableMetadata public function
ResourceResponse::__construct public function Constructor for ResourceResponse objects.
ResourceResponseTrait::$responseData protected property Response data that should be serialized.
ResourceResponseTrait::getResponseData public function Returns response data that should be serialized.