| @@ 95-116 (lines=22) @@ | ||
| 92 | * @param array $json |
|
| 93 | * @return array |
|
| 94 | */ |
|
| 95 | protected function hydrateCollectionResources(ResourceInterface $object, array $json) |
|
| 96 | { |
|
| 97 | $annotation = $this->getAnnotation($object, Collection::class); |
|
| 98 | ||
| 99 | if (!($annotation instanceof Collection)) { |
|
| 100 | return $json; |
|
| 101 | } |
|
| 102 | ||
| 103 | foreach ($annotation->properties() as $property) { |
|
| 104 | $array = $json[$property]; |
|
| 105 | $json[$property] = []; |
|
| 106 | foreach ($array as $resource) { |
|
| 107 | if ($resource === null) { |
|
| 108 | continue; |
|
| 109 | } |
|
| 110 | ||
| 111 | $json[$property][] = $this->hydrate($annotation->get($property), $resource); |
|
| 112 | } |
|
| 113 | } |
|
| 114 | ||
| 115 | return $json; |
|
| 116 | } |
|
| 117 | ||
| 118 | /** |
|
| 119 | * @param string $class |
|
| @@ 168-185 (lines=18) @@ | ||
| 165 | * @param ResourceInterface $object |
|
| 166 | * @return array |
|
| 167 | */ |
|
| 168 | protected function extractCollectionResources(array $json, ResourceInterface $object) |
|
| 169 | { |
|
| 170 | $annotation = $this->getAnnotation($object, Collection::class); |
|
| 171 | ||
| 172 | if (!($annotation instanceof Collection)) { |
|
| 173 | return $json; |
|
| 174 | } |
|
| 175 | ||
| 176 | foreach ($annotation->properties() as $property) { |
|
| 177 | $array = $json[$property]; |
|
| 178 | $json[$property] = []; |
|
| 179 | foreach ($array as $resource) { |
|
| 180 | $json[$property][] = $this->extract($annotation->get($property), $resource); |
|
| 181 | } |
|
| 182 | } |
|
| 183 | ||
| 184 | return $json; |
|
| 185 | } |
|
| 186 | ||
| 187 | /** |
|
| 188 | * @param ResourceInterface $object |
|