|
4 | 4 |
|
5 | 5 | namespace Patchlevel\Hydrator\Metadata; |
6 | 6 |
|
7 | | -use Patchlevel\Hydrator\Attribute\DataSubjectId; |
8 | 7 | use Patchlevel\Hydrator\Attribute\Ignore; |
9 | 8 | use Patchlevel\Hydrator\Attribute\Lazy; |
10 | 9 | use Patchlevel\Hydrator\Attribute\NormalizedName; |
11 | 10 | use Patchlevel\Hydrator\Attribute\PostHydrate; |
12 | 11 | use Patchlevel\Hydrator\Attribute\PreExtract; |
13 | | -use Patchlevel\Hydrator\Attribute\SensitiveData; |
14 | 12 | use Patchlevel\Hydrator\Guesser\BuiltInGuesser; |
15 | 13 | use Patchlevel\Hydrator\Guesser\Guesser; |
16 | 14 | use Patchlevel\Hydrator\Normalizer\ArrayNormalizer; |
@@ -73,11 +71,7 @@ public function metadata(string $class): ClassMetadata |
73 | 71 | throw new ClassNotFound($class); |
74 | 72 | } |
75 | 73 |
|
76 | | - $classMetadata = $this->getClassMetadata($reflectionClass); |
77 | | - |
78 | | - $this->validate($classMetadata); |
79 | | - |
80 | | - return $classMetadata; |
| 74 | + return $this->getClassMetadata($reflectionClass); |
81 | 75 | } |
82 | 76 |
|
83 | 77 | /** |
@@ -157,8 +151,6 @@ private function getPropertyMetadataList(ReflectionClass $reflectionClass): arra |
157 | 151 | $reflectionProperty, |
158 | 152 | $fieldName, |
159 | 153 | $this->getNormalizer($reflectionProperty), |
160 | | - $this->getSubjectId($reflectionProperty), |
161 | | - ...$this->getSensitiveData($reflectionProperty), |
162 | 154 | ); |
163 | 155 | } |
164 | 156 |
|
@@ -272,74 +264,14 @@ private function mergeMetadata(ClassMetadata $parent, ClassMetadata $child): Cla |
272 | 264 | $properties[$property->fieldName] = $property; |
273 | 265 | } |
274 | 266 |
|
275 | | - $mergedClassMetadata = new ClassMetadata( |
| 267 | + return new ClassMetadata( |
276 | 268 | $parent->reflection, |
277 | 269 | array_values($properties), |
278 | 270 | array_merge($parent->postHydrateCallbacks, $child->postHydrateCallbacks), |
279 | 271 | array_merge($parent->preExtractCallbacks, $child->preExtractCallbacks), |
280 | 272 | $child->lazy ?? $parent->lazy, |
| 273 | + array_merge($parent->extras, $child->extras), |
281 | 274 | ); |
282 | | - |
283 | | - $this->validate($mergedClassMetadata); |
284 | | - |
285 | | - return $mergedClassMetadata; |
286 | | - } |
287 | | - |
288 | | - private function getSubjectId(ReflectionProperty $reflectionProperty): string|null |
289 | | - { |
290 | | - $attributeReflectionList = $reflectionProperty->getAttributes(DataSubjectId::class); |
291 | | - |
292 | | - if (!$attributeReflectionList) { |
293 | | - return null; |
294 | | - } |
295 | | - |
296 | | - return $attributeReflectionList[0]->newInstance()->name; |
297 | | - } |
298 | | - |
299 | | - /** @return array{string|null, mixed, (callable(string, mixed):mixed)|null} */ |
300 | | - private function getSensitiveData(ReflectionProperty $reflectionProperty): array |
301 | | - { |
302 | | - $attributeReflectionList = $reflectionProperty->getAttributes(SensitiveData::class); |
303 | | - |
304 | | - if ($attributeReflectionList === []) { |
305 | | - return [null, null, null]; |
306 | | - } |
307 | | - |
308 | | - $attribute = $attributeReflectionList[0]->newInstance(); |
309 | | - |
310 | | - return [$attribute->subjectIdName, $attribute->fallback, $attribute->fallbackCallable]; |
311 | | - } |
312 | | - |
313 | | - private function validate(ClassMetadata $metadata): void |
314 | | - { |
315 | | - $subjectIds = []; |
316 | | - |
317 | | - foreach ($metadata->properties as $property) { |
318 | | - if ($property->isSensitiveData() && $property->isSubjectId()) { |
319 | | - throw new SubjectIdAndSensitiveDataConflict($metadata->className(), $property->propertyName()); |
320 | | - } |
321 | | - |
322 | | - if ($property->isSensitiveData() && !$metadata->hasSubjectIdIdentifier($property->sensitiveDataSubjectIdName)) { |
323 | | - throw new MissingDataSubjectId($metadata->className()); |
324 | | - } |
325 | | - |
326 | | - if (!$property->isSubjectId()) { |
327 | | - continue; |
328 | | - } |
329 | | - |
330 | | - $subjectIdIdentifier = $property->subjectIdName; |
331 | | - |
332 | | - if (array_key_exists($subjectIdIdentifier, $subjectIds)) { |
333 | | - throw new DuplicateSubjectIdIdentifier( |
334 | | - $metadata->className(), |
335 | | - $subjectIds[$subjectIdIdentifier], |
336 | | - $property->propertyName(), |
337 | | - $subjectIdIdentifier, |
338 | | - ); |
339 | | - } |
340 | | - |
341 | | - $subjectIds[$subjectIdIdentifier] = $property->propertyName(); |
342 | | - } |
343 | 275 | } |
344 | 276 |
|
345 | 277 | private function getNormalizer(ReflectionProperty $reflectionProperty): Normalizer|null |
|
0 commit comments