class ResourceResponse in JSON:API 8
Same name and namespace in other branches
- 8.2 src/ResourceResponse.php \Drupal\jsonapi\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.
@internal
Hierarchy
- class \Drupal\jsonapi\ResourceResponse extends \Symfony\Component\HttpFoundation\Response implements CacheableResponseInterface uses CacheableResponseTrait
Expanded class hierarchy of ResourceResponse
See also
\Drupal\rest\ModifiedResourceResponse
6 files declare their use of ResourceResponse
- EntityResource.php in src/
Controller/ EntityResource.php - ResourceResponseSubscriber.php in src/
EventSubscriber/ ResourceResponseSubscriber.php - ResourceResponseTestTrait.php in tests/
src/ Functional/ ResourceResponseTestTrait.php - ResourceResponseValidator.php in src/
EventSubscriber/ ResourceResponseValidator.php - ResourceTestBase.php in tests/
src/ Functional/ ResourceTestBase.php
File
- src/
ResourceResponse.php, line 21
Namespace
Drupal\jsonapiView source
class ResourceResponse extends Response implements CacheableResponseInterface {
use CacheableResponseTrait;
/**
* Response data that should be serialized.
*
* @var mixed
*/
protected $responseData;
/**
* 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, array $headers = []) {
$this->responseData = $data;
parent::__construct('', $status, $headers);
}
/**
* Returns response data that should be serialized.
*
* @return mixed
* Response data that should be serialized.
*/
public function getResponseData() {
return $this->responseData;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheableResponseTrait:: |
protected | property | The cacheability metadata. | |
CacheableResponseTrait:: |
public | function | ||
CacheableResponseTrait:: |
public | function | ||
ResourceResponse:: |
protected | property | Response data that should be serialized. | |
ResourceResponse:: |
public | function | Returns response data that should be serialized. | |
ResourceResponse:: |
public | function | Constructor for ResourceResponse objects. |