class ResourceResponse

Same name in this branch
  1. 8.9.x core/modules/rest/src/ResourceResponse.php \Drupal\rest\ResourceResponse
Same name in other branches
  1. 9 core/modules/jsonapi/src/ResourceResponse.php \Drupal\jsonapi\ResourceResponse
  2. 9 core/modules/rest/src/ResourceResponse.php \Drupal\rest\ResourceResponse
  3. 10 core/modules/jsonapi/src/ResourceResponse.php \Drupal\jsonapi\ResourceResponse
  4. 10 core/modules/rest/src/ResourceResponse.php \Drupal\rest\ResourceResponse
  5. 11.x core/modules/jsonapi/src/ResourceResponse.php \Drupal\jsonapi\ResourceResponse
  6. 11.x 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.

@internal JSON:API maintains no PHP API since its API is the HTTP API. This class may change at any time and this will break any dependencies on it.

Hierarchy

Expanded class hierarchy of ResourceResponse

See also

https://www.drupal.org/project/drupal/issues/3032787

jsonapi.api.php

\Drupal\rest\ModifiedResourceResponse

7 files declare their use of ResourceResponse
DefaultExceptionSubscriber.php in core/modules/jsonapi/src/EventSubscriber/DefaultExceptionSubscriber.php
EntityResource.php in core/modules/jsonapi/src/Controller/EntityResource.php
EntryPoint.php in core/modules/jsonapi/src/Controller/EntryPoint.php
FileUpload.php in core/modules/jsonapi/src/Controller/FileUpload.php
ResourceResponseSubscriber.php in core/modules/jsonapi/src/EventSubscriber/ResourceResponseSubscriber.php

... See full list

File

core/modules/jsonapi/src/ResourceResponse.php, line 25

Namespace

Drupal\jsonapi
View 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

Title Sort descending Modifiers Object type Summary
CacheableResponseTrait::$cacheabilityMetadata protected property The cacheability metadata.
CacheableResponseTrait::addCacheableDependency public function
CacheableResponseTrait::getCacheableMetadata public function
ResourceResponse::$responseData protected property Response data that should be serialized.
ResourceResponse::getResponseData public function Returns response data that should be serialized.
ResourceResponse::__construct public function Constructor for ResourceResponse objects.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.