1 | <?php |
||
14 | class Resource implements ElementInterface |
||
15 | { |
||
16 | use LinksTrait; |
||
17 | use MetaTrait; |
||
18 | |||
19 | /** |
||
20 | * @var mixed |
||
21 | */ |
||
22 | protected $data; |
||
23 | |||
24 | /** |
||
25 | * @var SerializerInterface |
||
26 | */ |
||
27 | protected $serializer; |
||
28 | |||
29 | /** |
||
30 | * A list of relationships to include. |
||
31 | * |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $includes = []; |
||
35 | |||
36 | /** |
||
37 | * A list of fields to restrict to. |
||
38 | * |
||
39 | * @var array|null |
||
40 | */ |
||
41 | protected $fields; |
||
42 | |||
43 | /** |
||
44 | * An array of Resources that should be merged into this one. |
||
45 | * |
||
46 | * @var Resource[] |
||
47 | */ |
||
48 | protected $merged = []; |
||
49 | |||
50 | /** |
||
51 | * @param mixed $data |
||
52 | * @param SerializerInterface $serializer |
||
53 | */ |
||
54 | public function __construct($data, SerializerInterface $serializer) |
||
55 | { |
||
56 | $this->data = $data; |
||
57 | $this->serializer = $serializer; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | public function getResources() |
||
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | public function toArray() |
||
97 | |||
98 | /** |
||
99 | * Check whether or not this resource is an identifier (i.e. does it have |
||
100 | * any data attached?). |
||
101 | * |
||
102 | * @return bool |
||
103 | */ |
||
104 | public function isIdentifier() |
||
108 | |||
109 | /** |
||
110 | * {@inheritdoc} |
||
111 | */ |
||
112 | public function toIdentifier() |
||
125 | |||
126 | /** |
||
127 | * Get the resource type. |
||
128 | * |
||
129 | * @return string |
||
130 | */ |
||
131 | public function getType() |
||
135 | |||
136 | /** |
||
137 | * Get the resource ID. |
||
138 | * |
||
139 | * @return string |
||
140 | */ |
||
141 | public function getId() |
||
149 | |||
150 | /** |
||
151 | * Get the resource attributes. |
||
152 | * |
||
153 | * @return array |
||
154 | */ |
||
155 | public function getAttributes() |
||
165 | |||
166 | /** |
||
167 | * Get the requested fields for this resource type. |
||
168 | * |
||
169 | * @return array|null |
||
170 | */ |
||
171 | protected function getOwnFields() |
||
179 | |||
180 | /** |
||
181 | * Filter the given fields array (attributes or relationships) according |
||
182 | * to the requested fieldset. |
||
183 | * |
||
184 | * @param array $fields |
||
185 | * @return array |
||
186 | */ |
||
187 | protected function filterFields(array $fields) |
||
195 | |||
196 | /** |
||
197 | * Merge the attributes of merged resources into an array of attributes. |
||
198 | * |
||
199 | * @param array $attributes |
||
200 | * @return array |
||
201 | */ |
||
202 | protected function mergeAttributes(array $attributes) |
||
210 | |||
211 | /** |
||
212 | * Get the resource relationships. |
||
213 | * |
||
214 | * @return Relationship[] |
||
215 | */ |
||
216 | public function getRelationships() |
||
222 | |||
223 | /** |
||
224 | * Get the resource relationships without considering requested ones. |
||
225 | * |
||
226 | * @return Relationship[] |
||
227 | */ |
||
228 | public function getUnfilteredRelationships() |
||
232 | |||
233 | /** |
||
234 | * Get the resource relationships as an array. |
||
235 | * |
||
236 | * @return array |
||
237 | */ |
||
238 | public function getRelationshipsAsArray() |
||
246 | |||
247 | /** |
||
248 | * Get an array of built relationships. |
||
249 | * |
||
250 | * @return Relationship[] |
||
251 | */ |
||
252 | protected function buildRelationships() |
||
270 | |||
271 | /** |
||
272 | * Merge the relationships of merged resources into an array of |
||
273 | * relationships. |
||
274 | * |
||
275 | * @param array $relationships |
||
276 | * @return array |
||
277 | */ |
||
278 | protected function mergeRelationships(array $relationships) |
||
286 | |||
287 | /** |
||
288 | * Convert the given array of Relationship objects into an array. |
||
289 | * |
||
290 | * @param Relationship[] $relationships |
||
291 | * @return array |
||
292 | */ |
||
293 | protected function convertRelationshipsToArray(array $relationships) |
||
299 | |||
300 | /** |
||
301 | * Merge a resource into this one. |
||
302 | * |
||
303 | * @param Resource $resource |
||
304 | */ |
||
305 | public function merge(Resource $resource) |
||
309 | |||
310 | /** |
||
311 | * {@inheritdoc} |
||
312 | */ |
||
313 | public function with($relationships) |
||
319 | |||
320 | /** |
||
321 | * {@inheritdoc} |
||
322 | */ |
||
323 | public function fields($fields) |
||
329 | |||
330 | /** |
||
331 | * @return mixed |
||
332 | */ |
||
333 | public function getData() |
||
337 | |||
338 | /** |
||
339 | * @param mixed $data |
||
340 | */ |
||
341 | public function setData($data) |
||
345 | |||
346 | /** |
||
347 | * @return SerializerInterface |
||
348 | */ |
||
349 | public function getSerializer() |
||
353 | |||
354 | /** |
||
355 | * @param SerializerInterface $serializer |
||
356 | */ |
||
357 | public function setSerializer(SerializerInterface $serializer) |
||
361 | } |
||
362 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.