comparison core/modules/jsonapi/src/ResourceResponse.php @ 18:af1871eacc83

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:33:08 +0100
parents
children
comparison
equal deleted inserted replaced
17:129ea1e6d783 18:af1871eacc83
1 <?php
2
3 namespace Drupal\jsonapi;
4
5 use Drupal\Core\Cache\CacheableResponseInterface;
6 use Drupal\Core\Cache\CacheableResponseTrait;
7 use Symfony\Component\HttpFoundation\Response;
8
9 /**
10 * Contains data for serialization before sending the response.
11 *
12 * We do not want to abuse the $content property on the Response class to store
13 * our response data. $content implies that the provided data must either be a
14 * string or an object with a __toString() method, which is not a requirement
15 * for data used here.
16 *
17 * @internal JSON:API maintains no PHP API since its API is the HTTP API. This
18 * class may change at any time and this will break any dependencies on it.
19 *
20 * @see https://www.drupal.org/project/jsonapi/issues/3032787
21 * @see jsonapi.api.php
22 *
23 * @see \Drupal\rest\ModifiedResourceResponse
24 */
25 class ResourceResponse extends Response implements CacheableResponseInterface {
26
27 use CacheableResponseTrait;
28
29 /**
30 * Response data that should be serialized.
31 *
32 * @var mixed
33 */
34 protected $responseData;
35
36 /**
37 * Constructor for ResourceResponse objects.
38 *
39 * @param mixed $data
40 * Response data that should be serialized.
41 * @param int $status
42 * The response status code.
43 * @param array $headers
44 * An array of response headers.
45 */
46 public function __construct($data = NULL, $status = 200, array $headers = []) {
47 $this->responseData = $data;
48 parent::__construct('', $status, $headers);
49 }
50
51 /**
52 * Returns response data that should be serialized.
53 *
54 * @return mixed
55 * Response data that should be serialized.
56 */
57 public function getResponseData() {
58 return $this->responseData;
59 }
60
61 }