-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: split Generator class in several classes (#35)
- Loading branch information
Showing
31 changed files
with
1,816 additions
and
875 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
namespace AutoMapper\Extractor; | ||
|
||
use AutoMapper\Exception\InvalidMappingException; | ||
use AutoMapper\MapperMetadataInterface; | ||
use AutoMapper\MapperGeneratorMetadataInterface; | ||
use AutoMapper\Transformer\CustomTransformer\CustomTransformersRegistry; | ||
use AutoMapper\Transformer\TransformerFactoryInterface; | ||
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface; | ||
|
@@ -22,6 +22,8 @@ | |
* Can use a NameConverter to use specific properties name in the target | ||
* | ||
* @author Joel Wurtz <[email protected]> | ||
* | ||
* @internal | ||
*/ | ||
final class FromSourceMappingExtractor extends MappingExtractor | ||
{ | ||
|
@@ -39,7 +41,7 @@ public function __construct( | |
parent::__construct($propertyInfoExtractor, $readInfoExtractor, $writeInfoExtractor, $transformerFactory, $customTransformerRegistry, $classMetadataFactory); | ||
} | ||
|
||
public function getPropertiesMapping(MapperMetadataInterface $mapperMetadata): array | ||
public function getPropertiesMapping(MapperGeneratorMetadataInterface $mapperMetadata): array | ||
{ | ||
$sourceProperties = $this->propertyInfoExtractor->getProperties($mapperMetadata->getSource()); | ||
|
||
|
@@ -83,6 +85,7 @@ public function getPropertiesMapping(MapperMetadataInterface $mapperMetadata): a | |
} | ||
|
||
$mapping[] = new PropertyMapping( | ||
$mapperMetadata, | ||
$this->getReadAccessor($mapperMetadata->getSource(), $mapperMetadata->getTarget(), $property), | ||
$this->getWriteMutator($mapperMetadata->getSource(), $mapperMetadata->getTarget(), $property), | ||
null, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
namespace AutoMapper\Extractor; | ||
|
||
use AutoMapper\Exception\InvalidMappingException; | ||
use AutoMapper\MapperMetadataInterface; | ||
use AutoMapper\MapperGeneratorMetadataInterface; | ||
use AutoMapper\Transformer\CustomTransformer\CustomTransformersRegistry; | ||
use AutoMapper\Transformer\TransformerFactoryInterface; | ||
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface; | ||
|
@@ -23,6 +23,8 @@ | |
* Can use a NameConverter to use specific properties name in the source | ||
* | ||
* @author Joel Wurtz <[email protected]> | ||
* | ||
* @internal | ||
*/ | ||
final class FromTargetMappingExtractor extends MappingExtractor | ||
{ | ||
|
@@ -40,7 +42,7 @@ public function __construct( | |
parent::__construct($propertyInfoExtractor, $readInfoExtractor, $writeInfoExtractor, $transformerFactory, $customTransformerRegistry, $classMetadataFactory); | ||
} | ||
|
||
public function getPropertiesMapping(MapperMetadataInterface $mapperMetadata): array | ||
public function getPropertiesMapping(MapperGeneratorMetadataInterface $mapperMetadata): array | ||
{ | ||
$targetProperties = array_unique($this->propertyInfoExtractor->getProperties($mapperMetadata->getTarget()) ?? []); | ||
|
||
|
@@ -78,6 +80,7 @@ public function getPropertiesMapping(MapperMetadataInterface $mapperMetadata): a | |
} | ||
|
||
$mapping[] = new PropertyMapping( | ||
$mapperMetadata, | ||
$this->getReadAccessor($mapperMetadata->getSource(), $mapperMetadata->getTarget(), $property), | ||
$this->getWriteMutator($mapperMetadata->getSource(), $mapperMetadata->getTarget(), $property, [ | ||
'enable_constructor_extraction' => false, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,43 +4,47 @@ | |
|
||
namespace AutoMapper\Extractor; | ||
|
||
use AutoMapper\MapperGeneratorMetadataInterface; | ||
use AutoMapper\Transformer\CustomTransformer\CustomTransformerInterface; | ||
use AutoMapper\Transformer\TransformerInterface; | ||
|
||
/** | ||
* Property mapping. | ||
* | ||
* @author Joel Wurtz <[email protected]> | ||
* | ||
* @internal | ||
*/ | ||
final class PropertyMapping | ||
final readonly class PropertyMapping | ||
{ | ||
public function __construct( | ||
public readonly ?ReadAccessor $readAccessor, | ||
public readonly ?WriteMutator $writeMutator, | ||
public readonly ?WriteMutator $writeMutatorConstructor, | ||
public MapperGeneratorMetadataInterface $mapperMetadata, | ||
public ?ReadAccessor $readAccessor, | ||
public ?WriteMutator $writeMutator, | ||
public ?WriteMutator $writeMutatorConstructor, | ||
/** @var TransformerInterface|class-string<CustomTransformerInterface> */ | ||
public readonly TransformerInterface|string $transformer, | ||
public readonly string $property, | ||
public readonly bool $checkExists = false, | ||
public readonly ?array $sourceGroups = null, | ||
public readonly ?array $targetGroups = null, | ||
public readonly ?int $maxDepth = null, | ||
public readonly bool $sourceIgnored = false, | ||
public readonly bool $targetIgnored = false, | ||
public readonly bool $isPublic = false, | ||
public TransformerInterface|string $transformer, | ||
public string $property, | ||
public bool $checkExists = false, | ||
public ?array $sourceGroups = null, | ||
public ?array $targetGroups = null, | ||
public ?int $maxDepth = null, | ||
public bool $sourceIgnored = false, | ||
public bool $targetIgnored = false, | ||
public bool $isPublic = false, | ||
) { | ||
} | ||
|
||
public function shouldIgnoreProperty(bool $shouldMapPrivateProperties = true): bool | ||
{ | ||
return $this->sourceIgnored | ||
return !$this->writeMutator | ||
|| $this->sourceIgnored | ||
|| $this->targetIgnored | ||
|| !($shouldMapPrivateProperties || $this->isPublic); | ||
} | ||
|
||
/** | ||
* @phpstan-assert-if-false TransformerInterface $this->transformer | ||
* @phpstan-assert-if-false !null $this->readAccessor | ||
* | ||
* @phpstan-assert-if-true string $this->transformer | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ | |
* Read accessor tell how to read from a property. | ||
* | ||
* @author Joel Wurtz <[email protected]> | ||
* | ||
* @internal | ||
*/ | ||
final class ReadAccessor | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,17 +4,20 @@ | |
|
||
namespace AutoMapper\Extractor; | ||
|
||
use AutoMapper\MapperGeneratorMetadataInterface; | ||
use AutoMapper\MapperMetadataInterface; | ||
use Symfony\Component\PropertyInfo\PropertyReadInfo; | ||
|
||
/** | ||
* Extracts mapping between two objects, only gives properties that have the same name. | ||
* | ||
* @author Joel Wurtz <[email protected]> | ||
* | ||
* @internal | ||
*/ | ||
class SourceTargetMappingExtractor extends MappingExtractor | ||
{ | ||
public function getPropertiesMapping(MapperMetadataInterface $mapperMetadata): array | ||
public function getPropertiesMapping(MapperGeneratorMetadataInterface $mapperMetadata): array | ||
{ | ||
$sourceProperties = $this->propertyInfoExtractor->getProperties($mapperMetadata->getSource()); | ||
$targetProperties = $this->propertyInfoExtractor->getProperties($mapperMetadata->getTarget()); | ||
|
@@ -61,7 +64,7 @@ public function getPropertiesMapping(MapperMetadataInterface $mapperMetadata): a | |
return $mapping; | ||
} | ||
|
||
private function toPropertyMapping(MapperMetadataInterface $mapperMetadata, string $property, bool $onlyCustomTransformer = false): PropertyMapping|null | ||
private function toPropertyMapping(MapperGeneratorMetadataInterface $mapperMetadata, string $property, bool $onlyCustomTransformer = false): PropertyMapping|null | ||
{ | ||
$targetMutatorConstruct = $this->getWriteMutator($mapperMetadata->getSource(), $mapperMetadata->getTarget(), $property, [ | ||
'enable_constructor_extraction' => true, | ||
|
@@ -85,6 +88,7 @@ private function toPropertyMapping(MapperMetadataInterface $mapperMetadata, stri | |
} | ||
|
||
return new PropertyMapping( | ||
$mapperMetadata, | ||
readAccessor: $this->getReadAccessor($mapperMetadata->getSource(), $mapperMetadata->getTarget(), $property), | ||
writeMutator: $this->getWriteMutator($mapperMetadata->getSource(), $mapperMetadata->getTarget(), $property, [ | ||
'enable_constructor_extraction' => false, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
* Writes mutator tell how to write to a property. | ||
* | ||
* @author Joel Wurtz <[email protected]> | ||
* | ||
* @internal | ||
*/ | ||
final class WriteMutator | ||
{ | ||
|
Oops, something went wrong.