Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/jsonapi/src/JsonApiResource/ResourceObjectData.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 |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\jsonapi\JsonApiResource; | |
4 | |
5 use Drupal\Component\Assertion\Inspector; | |
6 use Drupal\jsonapi\Exception\EntityAccessDeniedHttpException; | |
7 | |
8 /** | |
9 * Represents the primary data for individual and collection documents. | |
10 * | |
11 * @internal JSON:API maintains no PHP API. The API is the HTTP API. This class | |
12 * may change at any time and could break any dependencies on it. | |
13 * | |
14 * @see https://www.drupal.org/project/jsonapi/issues/3032787 | |
15 * @see jsonapi.api.php | |
16 */ | |
17 class ResourceObjectData extends Data { | |
18 | |
19 /** | |
20 * ResourceObjectData constructor. | |
21 * | |
22 * @param \Drupal\jsonapi\JsonApiResource\ResourceObject[]|\Drupal\jsonapi\Exception\EntityAccessDeniedHttpException[] $data | |
23 * Resource objects that are the primary data for the response. | |
24 * @param int $cardinality | |
25 * The number of resources that this collection may contain. | |
26 * | |
27 * @see \Drupal\jsonapi\JsonApiResource\Data::__construct | |
28 */ | |
29 public function __construct($data, $cardinality = -1) { | |
30 assert(Inspector::assertAllObjects($data, ResourceObject::class, EntityAccessDeniedHttpException::class)); | |
31 parent::__construct($data, $cardinality); | |
32 } | |
33 | |
34 /** | |
35 * Gets only data to be exposed. | |
36 * | |
37 * @return static | |
38 */ | |
39 public function getAccessible() { | |
40 $accessible_data = []; | |
41 foreach ($this->data as $resource_object) { | |
42 if (!$resource_object instanceof EntityAccessDeniedHttpException) { | |
43 $accessible_data[] = $resource_object; | |
44 } | |
45 } | |
46 return new static($accessible_data, $this->cardinality); | |
47 } | |
48 | |
49 /** | |
50 * Gets only data to be omitted. | |
51 * | |
52 * @return static | |
53 */ | |
54 public function getOmissions() { | |
55 $omitted_data = []; | |
56 foreach ($this->data as $resource_object) { | |
57 if ($resource_object instanceof EntityAccessDeniedHttpException) { | |
58 $omitted_data[] = $resource_object; | |
59 } | |
60 } | |
61 return new OmittedData($omitted_data); | |
62 } | |
63 | |
64 } |