| 1 | <?php |
||
| 11 | class CollectionHandler extends AbstractHandler implements HandlerInterface |
||
| 12 | { |
||
| 13 | 6 | public function hydrate(AnnotationInterface $annotation, array $json, ResourceInterface $object): array |
|
| 14 | { |
||
| 15 | 6 | if (!($annotation instanceof Collection)) { |
|
| 16 | return $json; |
||
| 17 | } |
||
| 18 | |||
| 19 | 6 | foreach ($annotation->properties() as $property) { |
|
| 20 | 6 | if (!isset($json[$property])) { |
|
| 21 | 1 | $json[$property] = []; |
|
| 22 | 1 | continue; |
|
| 23 | } |
||
| 24 | |||
| 25 | 5 | $array = $json[$property]; |
|
| 26 | |||
| 27 | 5 | if (!is_array($array)) { |
|
| 28 | continue; |
||
| 29 | } |
||
| 30 | |||
| 31 | 5 | $json[$property] = []; |
|
| 32 | 5 | foreach ($array as $resource) { |
|
| 33 | 5 | if ($resource === null) { |
|
| 34 | continue; |
||
| 35 | } |
||
| 36 | |||
| 37 | 5 | $json[$property][] = $this->getHydrator()->hydrate($annotation->get($property), $resource); |
|
| 38 | } |
||
| 39 | } |
||
| 40 | |||
| 41 | 6 | return $json; |
|
| 42 | } |
||
| 43 | |||
| 44 | 3 | public function extract(AnnotationInterface $annotation, ResourceInterface $object, array $json): array |
|
| 60 | } |
||
| 61 |