| @@ 73-90 (lines=18) @@ | ||
| 70 | * @param array $json |
|
| 71 | * @return array |
|
| 72 | */ |
|
| 73 | protected function hydrateNestedResources(ResourceInterface $object, array $json) |
|
| 74 | { |
|
| 75 | $annotation = $this->getAnnotation($object, Nested::class); |
|
| 76 | ||
| 77 | if (!($annotation instanceof Nested)) { |
|
| 78 | return $json; |
|
| 79 | } |
|
| 80 | ||
| 81 | foreach ($annotation->properties() as $property) { |
|
| 82 | if ($json[$property] === null) { |
|
| 83 | continue; |
|
| 84 | } |
|
| 85 | ||
| 86 | $json[$property] = $this->hydrate($annotation->get($property), $json[$property]); |
|
| 87 | } |
|
| 88 | ||
| 89 | return $json; |
|
| 90 | } |
|
| 91 | ||
| 92 | /** |
|
| 93 | * @param ResourceInterface $object |
|
| @@ 125-139 (lines=15) @@ | ||
| 122 | * @param array $json |
|
| 123 | * @return array |
|
| 124 | */ |
|
| 125 | protected function hydrateRenameResourceProperties(ResourceInterface $object, array $json) |
|
| 126 | { |
|
| 127 | $annotation = $this->getAnnotation($object, Rename::class); |
|
| 128 | ||
| 129 | if (!($annotation instanceof Rename)) { |
|
| 130 | return $json; |
|
| 131 | } |
|
| 132 | ||
| 133 | foreach ($annotation->properties() as $property) { |
|
| 134 | $json[$property] = $json[$annotation->get($property)]; |
|
| 135 | unset($json[$annotation->get($property)]); |
|
| 136 | } |
|
| 137 | ||
| 138 | return $json; |
|
| 139 | } |
|
| 140 | ||
| 141 | /** |
|
| 142 | * @param string $class |
|
| @@ 172-185 (lines=14) @@ | ||
| 169 | * @param ResourceInterface $object |
|
| 170 | * @return array |
|
| 171 | */ |
|
| 172 | protected function extractNestedResources(array $json, ResourceInterface $object) |
|
| 173 | { |
|
| 174 | $annotation = $this->getAnnotation($object, Nested::class); |
|
| 175 | ||
| 176 | if (!($annotation instanceof Nested)) { |
|
| 177 | return $json; |
|
| 178 | } |
|
| 179 | ||
| 180 | foreach ($annotation->properties() as $property) { |
|
| 181 | $json[$property] = $this->extract($annotation->get($property), $json[$property]); |
|
| 182 | } |
|
| 183 | ||
| 184 | return $json; |
|
| 185 | } |
|
| 186 | ||
| 187 | /** |
|
| 188 | * @param array $json |
|
| @@ 216-230 (lines=15) @@ | ||
| 213 | * @param ResourceInterface $object |
|
| 214 | * @return array |
|
| 215 | */ |
|
| 216 | protected function extractRenameResourceProperties(array $json, ResourceInterface $object) |
|
| 217 | { |
|
| 218 | $annotation = $this->getAnnotation($object, Rename::class); |
|
| 219 | ||
| 220 | if (!($annotation instanceof Rename)) { |
|
| 221 | return $json; |
|
| 222 | } |
|
| 223 | ||
| 224 | foreach ($annotation->properties() as $property) { |
|
| 225 | $json[$annotation->get($property)] = $json[$property]; |
|
| 226 | unset($json[$property]); |
|
| 227 | } |
|
| 228 | ||
| 229 | return $json; |
|
| 230 | } |
|
| 231 | ||
| 232 | /** |
|
| 233 | * @param ResourceInterface $object |
|