class ResourceResponse in Drupal 10
Same name in this branch
- 10 core/modules/jsonapi/src/ResourceResponse.php \Drupal\jsonapi\ResourceResponse
- 10 core/modules/rest/src/ResourceResponse.php \Drupal\rest\ResourceResponse
Same name and namespace in other branches
- 8 core/modules/rest/src/ResourceResponse.php \Drupal\rest\ResourceResponse
- 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
- class \Drupal\rest\ResourceResponse extends \Symfony\Component\HttpFoundation\Response implements \Drupal\Core\Cache\CacheableResponseInterface, \Drupal\rest\ResourceResponseInterface uses \Drupal\Core\Cache\CacheableResponseTrait, \Drupal\rest\ResourceResponseTrait
Expanded class hierarchy of ResourceResponse
See also
\Drupal\rest\ModifiedResourceResponse
6 files declare their use of ResourceResponse
- DBLogResource.php in core/modules/ dblog/ src/ Plugin/ rest/ resource/ DBLogResource.php 
- EntityResource.php in core/modules/ rest/ src/ Plugin/ rest/ resource/ EntityResource.php 
- NoSerializationClassTestResource.php in core/modules/ rest/ tests/ modules/ rest_test/ src/ Plugin/ rest/ resource/ NoSerializationClassTestResource.php 
- RequestHandlerTest.php in core/modules/ rest/ tests/ src/ Kernel/ RequestHandlerTest.php 
- ResourceResponseSubscriberTest.php in core/modules/ rest/ tests/ src/ Unit/ EventSubscriber/ ResourceResponseSubscriberTest.php 
File
- core/modules/ rest/ src/ ResourceResponse.php, line 21 
Namespace
Drupal\restView 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);
  }
}