1 | <?php declare(strict_types=1); |
||
32 | class DocumentWriter extends BaseWriter implements DocumentWriterInterface |
||
33 | { |
||
34 | /** |
||
35 | * @var array |
||
36 | */ |
||
37 | private $addedResources; |
||
38 | |||
39 | /** |
||
40 | * @inheritdoc |
||
41 | */ |
||
42 | 3 | public function setNullToData(): DocumentWriterInterface |
|
50 | |||
51 | /** |
||
52 | * @inheritdoc |
||
53 | */ |
||
54 | 6 | public function addIdentifierToData(IdentifierInterface $identifier): DocumentWriterInterface |
|
60 | |||
61 | /** |
||
62 | * @inheritdoc |
||
63 | */ |
||
64 | 53 | public function addResourceToData( |
|
72 | |||
73 | /** |
||
74 | * @inheritdoc |
||
75 | */ |
||
76 | 20 | public function addResourceToIncluded( |
|
94 | |||
95 | /** |
||
96 | * @inheritdoc |
||
97 | */ |
||
98 | 70 | protected function reset(): void |
|
104 | |||
105 | /** |
||
106 | * If full resource has not been added yet either to includes section. |
||
107 | * |
||
108 | * @param ResourceInterface $resource |
||
109 | * |
||
110 | * @return bool |
||
111 | */ |
||
112 | 20 | protected function hasNotBeenAdded(ResourceInterface $resource): bool |
|
116 | |||
117 | /** |
||
118 | * @param ResourceInterface $resource |
||
119 | * |
||
120 | * @return void |
||
121 | */ |
||
122 | 20 | protected function registerResource(ResourceInterface $resource): void |
|
128 | |||
129 | /** |
||
130 | * @param IdentifierInterface $identifier |
||
131 | * |
||
132 | * @return array |
||
133 | */ |
||
134 | 29 | protected function getIdentifierRepresentation(IdentifierInterface $identifier): array |
|
148 | |||
149 | /** |
||
150 | * @param ResourceInterface $resource |
||
151 | * |
||
152 | * @return array |
||
153 | */ |
||
154 | 19 | protected function getIdentifierRepresentationFromResource(ResourceInterface $resource): array |
|
165 | |||
166 | /** |
||
167 | * @param iterable $attributes |
||
168 | * |
||
169 | * @return array |
||
170 | */ |
||
171 | 54 | protected function getAttributesRepresentation(iterable $attributes): array |
|
180 | |||
181 | /** |
||
182 | * @param iterable $relationships |
||
183 | * |
||
184 | * @return array |
||
185 | */ |
||
186 | 54 | protected function getRelationshipsRepresentation(iterable $relationships): array |
|
197 | |||
198 | /** |
||
199 | * @param RelationshipInterface $relationship |
||
200 | * |
||
201 | * @return array |
||
202 | */ |
||
203 | 36 | protected function getRelationshipRepresentation(RelationshipInterface $relationship): array |
|
224 | |||
225 | /** |
||
226 | * @param RelationshipDataInterface $data |
||
227 | * |
||
228 | * @return array|null |
||
229 | */ |
||
230 | 29 | protected function getRelationshipDataRepresentation(RelationshipDataInterface $data): ?array |
|
231 | { |
||
232 | 29 | if ($data->isResource() === true) { |
|
233 | 19 | return $this->getIdentifierRepresentationFromResource($data->getResource()); |
|
234 | 26 | } elseif ($data->isIdentifier() === true) { |
|
235 | 1 | return $this->getIdentifierRepresentation($data->getIdentifier()); |
|
236 | 25 | } elseif ($data->isCollection() === true) { |
|
237 | 25 | $representation = []; |
|
238 | 25 | foreach ($data->getIdentifiers() as $identifier) { |
|
239 | 23 | assert($identifier instanceof IdentifierInterface); |
|
240 | 23 | $representation[] = $this->getIdentifierRepresentation($identifier); |
|
241 | } |
||
242 | |||
243 | 25 | return $representation; |
|
244 | } |
||
245 | |||
246 | assert($data->isNull() === true); |
||
247 | |||
248 | return null; |
||
249 | } |
||
250 | |||
251 | /** |
||
252 | * @param ResourceInterface $resource |
||
253 | * @param FieldSetFilterInterface $filter |
||
254 | * |
||
255 | * @return array |
||
256 | */ |
||
257 | 54 | protected function getResourceRepresentation(ResourceInterface $resource, FieldSetFilterInterface $filter): array |
|
288 | |||
289 | /** |
||
290 | * @param array $representation |
||
291 | * |
||
292 | * @return void |
||
293 | */ |
||
294 | 59 | private function addToData(array $representation): void |
|
306 | |||
307 | /** |
||
308 | * @param array $representation |
||
309 | * |
||
310 | * @return void |
||
311 | */ |
||
312 | 19 | private function addToIncluded(array $representation): void |
|
316 | } |
||
317 |