@@ 97-118 (lines=22) @@ | ||
94 | * @param array $json |
|
95 | * @return array |
|
96 | */ |
|
97 | protected function hydrateCollectionResources(ResourceInterface $object, array $json) |
|
98 | { |
|
99 | $annotation = $this->getAnnotation($object, Collection::class); |
|
100 | ||
101 | if (!($annotation instanceof Collection)) { |
|
102 | return $json; |
|
103 | } |
|
104 | ||
105 | foreach ($annotation->properties() as $property) { |
|
106 | $array = $json[$property]; |
|
107 | $json[$property] = []; |
|
108 | foreach ($array as $resource) { |
|
109 | if ($resource === null) { |
|
110 | continue; |
|
111 | } |
|
112 | ||
113 | $json[$property][] = $this->hydrate($annotation->get($property), $resource); |
|
114 | } |
|
115 | } |
|
116 | ||
117 | return $json; |
|
118 | } |
|
119 | ||
120 | /** |
|
121 | * @param ResourceInterface $object |
|
@@ 192-209 (lines=18) @@ | ||
189 | * @param ResourceInterface $object |
|
190 | * @return array |
|
191 | */ |
|
192 | protected function extractCollectionResources(array $json, ResourceInterface $object) |
|
193 | { |
|
194 | $annotation = $this->getAnnotation($object, Collection::class); |
|
195 | ||
196 | if (!($annotation instanceof Collection)) { |
|
197 | return $json; |
|
198 | } |
|
199 | ||
200 | foreach ($annotation->properties() as $property) { |
|
201 | $array = $json[$property]; |
|
202 | $json[$property] = []; |
|
203 | foreach ($array as $resource) { |
|
204 | $json[$property][] = $this->extract($annotation->get($property), $resource); |
|
205 | } |
|
206 | } |
|
207 | ||
208 | return $json; |
|
209 | } |
|
210 | ||
211 | /** |
|
212 | * @param array $json |