annotate core/modules/jsonapi/src/ResourceResponse.php @ 5:12f9dff5fda9 tip

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