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