diff --git a/src/Transformer/Implementation/ObjectToObjectTransformer.php b/src/Transformer/Implementation/ObjectToObjectTransformer.php index c48a524..b53a090 100644 --- a/src/Transformer/Implementation/ObjectToObjectTransformer.php +++ b/src/Transformer/Implementation/ObjectToObjectTransformer.php @@ -43,7 +43,6 @@ use Rekalogika\Mapper\Transformer\TransformerInterface; use Rekalogika\Mapper\Transformer\TypeMapping; use Rekalogika\Mapper\Transformer\Util\ReaderWriter; -use Rekalogika\Mapper\Util\ClassUtil; use Rekalogika\Mapper\Util\TypeFactory; use Rekalogika\Mapper\Util\TypeGuesser; use Symfony\Component\PropertyAccess\PropertyAccessorInterface; @@ -383,7 +382,7 @@ private function generateConstructorArguments( if (($extraTargetValues = $context(ExtraTargetValues::class)) !== null) { $targetValues = $extraTargetValues - ->getArgumentsForClass(ClassUtil::getAllClassesFromObject($objectToObjectMetadata->getTargetClass())); + ->getArgumentsForClass($objectToObjectMetadata->getAllTargetClasses()); /** @var mixed $value */ foreach ($targetValues as $property => $value) { diff --git a/src/Transformer/ObjectToObjectMetadata/Implementation/ObjectToObjectMetadataFactory.php b/src/Transformer/ObjectToObjectMetadata/Implementation/ObjectToObjectMetadataFactory.php index 871f84e..4e12579 100644 --- a/src/Transformer/ObjectToObjectMetadata/Implementation/ObjectToObjectMetadataFactory.php +++ b/src/Transformer/ObjectToObjectMetadata/Implementation/ObjectToObjectMetadataFactory.php @@ -162,6 +162,7 @@ class: $targetClass, sourceClass: $sourceClass, targetClass: $targetClass, providedTargetClass: $providedTargetClass, + allTargetClasses: ClassUtil::getAllClassesFromObject($targetClass), sourceAllowsDynamicProperties: $sourceClassMetadata->hasReadableDynamicProperties(), targetAllowsDynamicProperties: $targetClassMetadata->hasWritableDynamicProperties(), sourceProperties: $effectivePropertiesToMap, diff --git a/src/Transformer/ObjectToObjectMetadata/ObjectToObjectMetadata.php b/src/Transformer/ObjectToObjectMetadata/ObjectToObjectMetadata.php index a668fea..69fd19f 100644 --- a/src/Transformer/ObjectToObjectMetadata/ObjectToObjectMetadata.php +++ b/src/Transformer/ObjectToObjectMetadata/ObjectToObjectMetadata.php @@ -52,6 +52,7 @@ * @param class-string $sourceClass * @param class-string $targetClass Effective target class after resolving inheritance map * @param class-string $providedTargetClass + * @param list $allTargetClasses * @param list $allPropertyMappings * @param array $targetProxySkippedProperties * @param list $sourceProperties List of the source properties. Used by `ObjectToObjectTransformer` to determine if a property is a dynamic property. A property not listed here is considered dynamic. @@ -60,6 +61,7 @@ public function __construct( private string $sourceClass, private string $targetClass, private string $providedTargetClass, + private array $allTargetClasses, private bool $sourceAllowsDynamicProperties, private bool $targetAllowsDynamicProperties, private array $sourceProperties, @@ -121,6 +123,7 @@ public function withTargetProxy( sourceClass: $this->sourceClass, targetClass: $this->targetClass, providedTargetClass: $this->providedTargetClass, + allTargetClasses: $this->allTargetClasses, sourceAllowsDynamicProperties: $this->sourceAllowsDynamicProperties, targetAllowsDynamicProperties: $this->targetAllowsDynamicProperties, sourceProperties: $this->sourceProperties, @@ -146,6 +149,7 @@ public function withReasonCannotUseProxy( sourceClass: $this->sourceClass, targetClass: $this->targetClass, providedTargetClass: $this->providedTargetClass, + allTargetClasses: $this->allTargetClasses, sourceAllowsDynamicProperties: $this->sourceAllowsDynamicProperties, targetAllowsDynamicProperties: $this->targetAllowsDynamicProperties, sourceProperties: $this->sourceProperties, @@ -188,6 +192,14 @@ public function getProvidedTargetClass(): string return $this->providedTargetClass; } + /** + * @return list + */ + public function getAllTargetClasses(): array + { + return $this->allTargetClasses; + } + public function isInstantiable(): bool { return $this->instantiable;