Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
priyadi committed Oct 14, 2024
1 parent 6f2223c commit b292764
Show file tree
Hide file tree
Showing 7 changed files with 1,135 additions and 1,029 deletions.
4 changes: 2 additions & 2 deletions src/Transformer/Implementation/ObjectToObjectTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
use Rekalogika\Mapper\Transformer\ObjectToObjectMetadata\ObjectToObjectMetadataFactoryInterface;
use Rekalogika\Mapper\Transformer\TransformerInterface;
use Rekalogika\Mapper\Transformer\TypeMapping;
use Rekalogika\Mapper\Transformer\Util\ObjectToObjectTransformerWorker;
use Rekalogika\Mapper\Transformer\Util\ObjectMapper;
use Rekalogika\Mapper\Util\TypeFactory;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Symfony\Component\PropertyInfo\Type;
Expand Down Expand Up @@ -100,7 +100,7 @@ public function transform(
throw new InvalidArgumentException(\sprintf('The target must be an object, "%s" given.', get_debug_type($target)), context: $context);
}

$worker = new ObjectToObjectTransformerWorker(
$worker = new ObjectMapper(
metadata: $objectToObjectMetadata,
mainTransformer: $this->getMainTransformer(),
propertyMapperLocator: $this->propertyMapperLocator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,14 @@ class: $targetClass,
$sourceAttributes = new SourcePropertyAttributes($sourcePropertyMetadata->getAttributes());
$targetAttributes = new TargetPropertyAttributes($targetPropertyMetadata->getAttributes());

// generate id

$id = hash('sha256', $sourceClass . $sourceProperty . $targetClass . $targetProperty);

// instantiate property mapping

$propertyMapping = new PropertyMapping(
id: $id,
sourceProperty: $sourcePropertyMetadata->getReadMode() !== ReadMode::None ? $sourceProperty : null,
targetProperty: $targetProperty,
sourceTypes: $sourcePropertyMetadata->getTypes(),
Expand Down
11 changes: 11 additions & 0 deletions src/Transformer/ObjectToObjectMetadata/PropertyMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
* @param 'int'|'float'|'string'|'bool'|'null'|null $targetScalarType
*/
public function __construct(
private string $id,
private ?string $sourceProperty,
private string $targetProperty,
array $sourceTypes,
Expand Down Expand Up @@ -75,6 +76,11 @@ public function __construct(
$this->targetTypes = array_values($targetTypes);
}

public function getId(): string
{
return $this->id;
}

public function getCompatibleSourceType(Type $type): ?Type
{
foreach ($this->sourceTypes as $sourceType) {
Expand Down Expand Up @@ -117,6 +123,11 @@ public function getPropertyMapper(): ?ServiceMethodSpecification
return $this->propertyMapper;
}

public function hasPropertyMapper(): bool
{
return $this->propertyMapper !== null;
}

/**
* If set, set the property directly, without delegating to the main
* transformer
Expand Down
Loading

0 comments on commit b292764

Please sign in to comment.