|
16 | 16 | use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException;
|
17 | 17 | use Symfony\Component\PropertyAccess\Exception\UninitializedPropertyException;
|
18 | 18 | use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
| 19 | +use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor; |
| 20 | +use Symfony\Component\PropertyInfo\PropertyInfoExtractor; |
19 | 21 | use Symfony\Component\PropertyInfo\Type;
|
20 | 22 | use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
21 | 23 | use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
@@ -358,14 +360,14 @@ private function dehydrateValue(mixed $value, LivePropMetadata $propMetadata, ob
|
358 | 360 | if (!$this->isValueValidDehydratedValue($value)) {
|
359 | 361 | $badKeys = $this->getNonScalarKeys($value, $propMetadata->getName());
|
360 | 362 | $badKeysText = implode(', ', array_map(fn ($key) => sprintf('%s: %s', $key, $badKeys[$key]), array_keys($badKeys)));
|
361 |
| - throw new \LogicException(sprintf('The LiveProp "%s" on component "%s" is an array, but it contains one or more keys that are not scalars: %s', $propMetadata->getName(), $parentObject::class, $badKeysText)); |
| 363 | + throw new \LogicException(throw new \LogicException(sprintf('Unable to dehydrate value of type "%s" for property "%s" on component "%s". Change this to a simpler type of an object that can be dehydrated. Or set the hydrateWith/dehydrateWith options in LiveProp or set "useSerializerForHydration: true" on the LiveProp to use the serializer.', get_debug_type($value), $propMetadata->getName(), $parentObject::class))); |
362 | 364 | }
|
363 | 365 |
|
364 | 366 | return $value;
|
365 | 367 | }
|
366 | 368 |
|
367 | 369 | if (!\is_object($value)) {
|
368 |
| - throw new \LogicException(sprintf('The "%s" object has a hydrateMethod of "%s" but the method does not exist.', $parentObject::class, $propMetadata->hydrateMethod())); |
| 370 | + throw new \LogicException(sprintf('Unable to dehydrate value of type "%s" for property "%s" on component "%s". Change this to a simpler type of an object that can be dehydrated. Or set the hydrateWith/dehydrateWith options in LiveProp or set "useSerializerForHydration: true" on the LiveProp to use the serializer.', get_debug_type($value), $propMetadata->getName(), $parentObject::class)); |
369 | 371 | }
|
370 | 372 |
|
371 | 373 | if (!$propMetadata->getType() || $propMetadata->isBuiltIn()) {
|
@@ -395,10 +397,10 @@ private function dehydrateObjectValue(object $value, string $classType, ?string
|
395 | 397 | }
|
396 | 398 |
|
397 | 399 | $dehydratedObjectValues = [];
|
398 |
| - foreach ((new \ReflectionClass($classType))->getProperties() as $property) { |
399 |
| - $propertyValue = $this->propertyAccessor->getValue($value, $property->getName()); |
400 |
| - $propMetadata = $this->liveComponentMetadataFactory->createLivePropMetadata($classType, $property->getName(), $property, new LiveProp()); |
401 |
| - $dehydratedObjectValues[$property->getName()] = $this->dehydrateValue($propertyValue, $propMetadata, $parentObject); |
| 400 | + foreach ((new PropertyInfoExtractor([new ReflectionExtractor()]))->getProperties($classType) as $property) { |
| 401 | + $propertyValue = $this->propertyAccessor->getValue($value, $property); |
| 402 | + $propMetadata = $this->liveComponentMetadataFactory->createLivePropMetadata($classType, $property, new \ReflectionProperty($classType, $property), new LiveProp()); |
| 403 | + $dehydratedObjectValues[$property] = $this->dehydrateValue($propertyValue, $propMetadata, $parentObject); |
402 | 404 | }
|
403 | 405 |
|
404 | 406 | return $dehydratedObjectValues;
|
@@ -479,8 +481,8 @@ private function hydrateObjectValue(mixed $value, string $className, bool $allow
|
479 | 481 | if (\is_array($value)) {
|
480 | 482 | $object = new $className();
|
481 | 483 | foreach ($value as $propertyName => $propertyValue) {
|
482 |
| - $reflexionClass = new \ReflectionClass($className); |
483 |
| - $property = $reflexionClass->getProperty($propertyName); |
| 484 | + $reflectionClass = new \ReflectionClass($className); |
| 485 | + $property = $reflectionClass->getProperty($propertyName); |
484 | 486 | $propMetadata = $this->liveComponentMetadataFactory->createLivePropMetadata($className, $propertyName, $property, new LiveProp());
|
485 | 487 | $this->propertyAccessor->setValue($object, $propertyName, $this->hydrateValue($propertyValue, $propMetadata, $component));
|
486 | 488 | }
|
|
0 commit comments