Skip to content

Commit

Permalink
optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
priyadi committed Oct 12, 2024
1 parent 2a9c2a7 commit ea6fad2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Transformer/Implementation/ObjectToObjectTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class: $targetClass,
sourceClass: $sourceClass,
targetClass: $targetClass,
providedTargetClass: $providedTargetClass,
allTargetClasses: ClassUtil::getAllClassesFromObject($targetClass),
sourceAllowsDynamicProperties: $sourceClassMetadata->hasReadableDynamicProperties(),
targetAllowsDynamicProperties: $targetClassMetadata->hasWritableDynamicProperties(),
sourceProperties: $effectivePropertiesToMap,
Expand Down
12 changes: 12 additions & 0 deletions src/Transformer/ObjectToObjectMetadata/ObjectToObjectMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<class-string> $allTargetClasses
* @param list<PropertyMapping> $allPropertyMappings
* @param array<string,true> $targetProxySkippedProperties
* @param list<string> $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.
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -188,6 +192,14 @@ public function getProvidedTargetClass(): string
return $this->providedTargetClass;
}

/**
* @return list<class-string>
*/
public function getAllTargetClasses(): array
{
return $this->allTargetClasses;
}

public function isInstantiable(): bool
{
return $this->instantiable;
Expand Down

0 comments on commit ea6fad2

Please sign in to comment.