@@ 13-32 (lines=20) @@ | ||
10 | ||
11 | class CollectionHandler extends AbstractHandler implements HandlerInterface |
|
12 | { |
|
13 | public function hydrate(AnnotationInterface $annotation, array $json, ResourceInterface $object): array |
|
14 | { |
|
15 | if (!($annotation instanceof Collection)) { |
|
16 | return $json; |
|
17 | } |
|
18 | ||
19 | foreach ($annotation->properties() as $property) { |
|
20 | $array = $json[$property]; |
|
21 | $json[$property] = []; |
|
22 | foreach ($array as $resource) { |
|
23 | if ($resource === null) { |
|
24 | continue; |
|
25 | } |
|
26 | ||
27 | $json[$property][] = $this->getHydrator()->hydrate($annotation->get($property), $resource); |
|
28 | } |
|
29 | } |
|
30 | ||
31 | return $json; |
|
32 | } |
|
33 | ||
34 | public function extract(AnnotationInterface $annotation, ResourceInterface $object, array $json): array |
|
35 | { |
|
@@ 34-49 (lines=16) @@ | ||
31 | return $json; |
|
32 | } |
|
33 | ||
34 | public function extract(AnnotationInterface $annotation, ResourceInterface $object, array $json): array |
|
35 | { |
|
36 | if (!($annotation instanceof Collection)) { |
|
37 | return $json; |
|
38 | } |
|
39 | ||
40 | foreach ($annotation->properties() as $property) { |
|
41 | $array = $json[$property]; |
|
42 | $json[$property] = []; |
|
43 | foreach ($array as $resource) { |
|
44 | $json[$property][] = $this->getHydrator()->extract($annotation->get($property), $resource); |
|
45 | } |
|
46 | } |
|
47 | ||
48 | return $json; |
|
49 | } |
|
50 | } |
|
51 |