From ea6fad2a2fb7e35e0b2e426eb5dcb132a9e1ec05 Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo <1102197+priyadi@users.noreply.github.com> Date: Sun, 13 Oct 2024 00:49:14 +0700 Subject: [PATCH] optimization --- .../Implementation/ObjectToObjectTransformer.php | 3 +-- .../Implementation/ObjectToObjectMetadataFactory.php | 1 + .../ObjectToObjectMetadata.php | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Transformer/Implementation/ObjectToObjectTransformer.php b/src/Transformer/Implementation/ObjectToObjectTransformer.php index c48a5248..b53a0909 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 871f84ed..4e125794 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 a668fea3..69fd19fd 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;