Skip to content

Commit e23c078

Browse files
committed
fix: Corrected matching strategy
1 parent 34bc2f8 commit e23c078

28 files changed

+204
-391
lines changed

README.md

+12-9
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,20 @@ The behavior of the `#[TargetProperty()]` attribute depends on the class in whic
1414

1515
##### NAME
1616

17-
| Declaration place | Normalization | Denormalization | Mapping | Transformation |
18-
|:-:|:-:|:-:|:-:|:-:|
19-
| **Source** | Source: ✖️<br>Target: ✖️ | Source: ✔️<br>Target: ✖️ | Source: ✖️<br>Target: ✔️ | Source: ✖️<br>Target: ✔️ |
20-
| **Target** | Source: ✖️<br>Target: ✔️ | Source: ✖️<br>Target: ✖️ | Source: ✔️<br>Target: ✖️ | Source: ✔️<br>Target: ✖️ |
17+
Target Property attribute works like `Symfony\SerializedName` for Normalization, Denormalization and Transformation. It changes property name when data are normalized.
2118

22-
##### PATH
19+
| Declaration place | Normalization | Denormalization | Transformation |
20+
|:-:|:-:|:-:|:-:|
21+
| **Source** | Source: ✖️<br>Target: ✖️ | Source: ✔️<br>Target: ✖️ | Source: ✔️<br>Target: ✖️ |
22+
| **Target** | Source: ✖️<br>Target: ✔️ | Source: ✖️<br>Target: ✖️ | Source: ✖️<br>Target: ✔️ |
23+
24+
Target Property attribute links properties from different blueprints for Mapping. It works with other processes or alone.
25+
26+
| Declaration place | Mapping |
27+
|:-:|:-:|
28+
| **Source** | Source: ✖️<br>Target: ✔️ |
29+
| **Target** | Source: ✔️<br>Target: ✖️ |
2330

24-
| Declaration place | Normalization | Denormalization | Mapping | Transformation |
25-
|:-:|:-:|:-:|:-:|:-:|
26-
| **Source** | Source: ✖️<br>Target: ✖️ | Source: ✔️<br>Target: ✖️ | Source: ✖️<br>Target: ➖ | Source: ✖️<br>Target: ➖ |
27-
| **Target** | Source: ✖️<br>Target: ➖ | Source: ✖️<br>Target: ✖️ | Source: ➖<br>Target: ✖️ | Source: ✔️<br>Target: ✖️ |
2831

2932
###### legend: ✖️ - *has no effect*, ✔️ - *affects*, ➖ - *not implemented*
3033

src/Mapper/Application/Attribute/Accessor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(
2727
) {
2828
}
2929

30-
public function validate(\ReflectionProperty|\ReflectionClass $reflection): void
30+
public function validate(\ReflectionProperty|\ReflectionParameter|\ReflectionClass $reflection): void
3131
{
3232
// todo implement
3333
}

src/Mapper/Application/Attribute/ApplyToCollectionItem.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct(
2121
}
2222

2323
/** @param \ReflectionProperty $reflection */
24-
public function validate(\ReflectionProperty|\ReflectionClass $reflection): void
24+
public function validate(\ReflectionProperty|\ReflectionParameter|\ReflectionClass $reflection): void
2525
{
2626
// $class = $reflection->getDeclaringClass();
2727

src/Mapper/Application/Attribute/Attributes.md

-44
This file was deleted.

src/Mapper/Application/Attribute/Callback.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function __construct(
109109
) {
110110
}
111111

112-
public function validate(\ReflectionProperty|\ReflectionClass $reflection): void
112+
public function validate(\ReflectionProperty|\ReflectionParameter|\ReflectionClass $reflection): void
113113
{
114114
// todo: update the list of available placeholders
115115
// if (str_replace([

src/Mapper/Application/Attribute/Discriminator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(
3333
) {
3434
}
3535

36-
public function validate(\ReflectionProperty|\ReflectionClass $reflection): void
36+
public function validate(\ReflectionProperty|\ReflectionParameter|\ReflectionClass $reflection): void
3737
{
3838
// todo implement
3939
}

src/Mapper/Application/Attribute/Groups.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(
2222
) {
2323
}
2424

25-
public function validate(\ReflectionProperty|\ReflectionClass $reflection): void
25+
public function validate(\ReflectionProperty|\ReflectionParameter|\ReflectionClass $reflection): void
2626
{
2727
// todo implement
2828
}

src/Mapper/Application/Attribute/Ignore.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __construct(
2323
) {
2424
}
2525

26-
public function validate(\ReflectionProperty|\ReflectionClass $reflection): void
26+
public function validate(\ReflectionProperty|\ReflectionParameter|\ReflectionClass $reflection): void
2727
{
2828
// todo implement
2929
}

src/Mapper/Application/Attribute/MaxDepth.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct(
2424
) {
2525
}
2626

27-
public function validate(\ReflectionProperty|\ReflectionClass $reflection): void
27+
public function validate(\ReflectionProperty|\ReflectionParameter|\ReflectionClass $reflection): void
2828
{
2929
// todo implement
3030
}

src/Mapper/Application/Attribute/SimpleObject.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(
3030
) {
3131
}
3232

33-
public function validate(\ReflectionProperty|\ReflectionClass $reflection): void
33+
public function validate(\ReflectionProperty|\ReflectionParameter|\ReflectionClass $reflection): void
3434
{
3535
// todo implement
3636
}

src/Mapper/Application/Attribute/TargetProperty.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
namespace PBaszak\UltraMapper\Mapper\Application\Attribute;
66

77
use PBaszak\UltraMapper\Mapper\Application\Contract\AttributeInterface;
8-
use PBaszak\UltraMapper\Mapper\Application\Contract\TypeInterface;
98
use PBaszak\UltraMapper\Mapper\Application\Exception\ThrowAttributeValidationExceptionTrait;
9+
use PBaszak\UltraMapper\Mapper\Domain\Model\Process;
1010

11-
#[\Attribute(\Attribute::TARGET_PROPERTY)]
11+
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_PARAMETER | \Attribute::IS_REPEATABLE)]
1212
class TargetProperty implements AttributeInterface
1313
{
1414
use ThrowAttributeValidationExceptionTrait;
@@ -19,10 +19,10 @@ class TargetProperty implements AttributeInterface
1919
public const TRANSFORMATION = 8; // 1000
2020

2121
public const PROCESS_TYPE_MAP = [
22-
TypeInterface::DENORMALIZATION_PROCESS => self::DENORMALIZATION,
23-
TypeInterface::NORMALIZATION_PROCESS => self::NORMALIZATION,
24-
TypeInterface::MAPPING_PROCESS => self::MAPPING,
25-
TypeInterface::TRANSFORMATION_PROCESS => self::TRANSFORMATION,
22+
Process::DENORMALIZATION_PROCESS => self::DENORMALIZATION,
23+
Process::NORMALIZATION_PROCESS => self::NORMALIZATION,
24+
Process::MAPPING_PROCESS => self::MAPPING,
25+
Process::TRANSFORMATION_PROCESS => self::TRANSFORMATION,
2626
];
2727

2828
/**
@@ -33,14 +33,14 @@ class TargetProperty implements AttributeInterface
3333
*/
3434
public function __construct(
3535
public readonly string $name,
36-
public readonly int $useNameFor = self::MAPPING | self::DENORMALIZATION | self::NORMALIZATION,
36+
public readonly int $useNameFor = self::DENORMALIZATION | self::NORMALIZATION | self::TRANSFORMATION | self::MAPPING,
3737
public readonly ?string $path = null,
38-
public readonly int $usePathFor = self::DENORMALIZATION,
38+
public readonly int $usePathFor = self::DENORMALIZATION | self::NORMALIZATION | self::TRANSFORMATION | self::MAPPING,
3939
public readonly array $options = []
4040
) {
4141
}
4242

43-
public function validate(\ReflectionProperty|\ReflectionClass $reflection): void
43+
public function validate(\ReflectionProperty|\ReflectionParameter|\ReflectionClass $reflection): void
4444
{
4545
// there cannot be two target properties with the same processType
4646
// todo implement

src/Mapper/Application/Contract/AttributeInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77
interface AttributeInterface
88
{
9-
public function validate(\ReflectionProperty|\ReflectionClass $reflection): void;
9+
public function validate(\ReflectionProperty|\ReflectionParameter|\ReflectionClass $reflection): void;
1010
}

src/Mapper/Application/Contract/ModificatorInterface.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace PBaszak\UltraMapper\Mapper\Application\Contract;
66

77
use PBaszak\UltraMapper\Blueprint\Application\Model\Blueprint;
8+
use PBaszak\UltraMapper\Mapper\Domain\Model\Process;
89

910
/**
1011
* The interface is used to handle modifiers to be used to create
@@ -25,10 +26,9 @@ public function getModifiers(): array;
2526
* Prepare the blueprint for the mapping class. Called before
2627
* matching properties.
2728
*
28-
* @param string<"normalization"|"denormalization"|"transformation"|"mapping"> $processType
29-
* @param string<"origin"|"source"|"target"> $processUse
29+
* @param string<"origin"|"source"|"target"> $processUse
3030
*/
31-
public function prepareBlueprint(Blueprint $blueprint, string $processType, string $processUse): void;
31+
public function prepareBlueprint(Blueprint $blueprint, Process $processType, string $processUse): void;
3232

3333
public function modifyBlueprints(): void;
3434
}

src/Mapper/Application/Contract/TypeInterface.php

-24
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,6 @@ interface TypeInterface
1818
public const NORMALIZED_TYPE = 'normalized';
1919
public const DENORMALIZED_TYPE = 'denormalized';
2020

21-
/**
22-
* Mapping denormalized data to normalized data.
23-
* Like from class object to array. As example: DTO to array.
24-
*/
25-
public const NORMALIZATION_PROCESS = 'normalization';
26-
27-
/**
28-
* Mapping normalized data to denormalized data.
29-
* From array to class object. As example: array to Entity.
30-
*/
31-
public const DENORMALIZATION_PROCESS = 'denormalization';
32-
33-
/**
34-
* Mapping denormalized data to denormalized data.
35-
* Like from class object to class object. As example: DTO to Entity.
36-
*/
37-
public const MAPPING_PROCESS = 'mapping';
38-
39-
/**
40-
* Mapping normalized data to normalized data.
41-
* From array to array, but You can add callbacks or other modifications.
42-
*/
43-
public const TRANSFORMATION_PROCESS = 'transformation';
44-
4521
/**
4622
* In some cases You would like to override the default blueprint class for
4723
* one of the sides of the mapping process. This method allows you to do that.

src/Mapper/Application/Service/Mapper.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,15 @@ public function map(
5252
TypeInterface $to,
5353
bool $isCollection = false
5454
): Envelope {
55-
$mapper = $this->getMapper($data, $blueprintClass, $from, $to, $isCollection);
55+
$mapper = $this->getMapper($blueprintClass, $from, $to, $isCollection);
5656

57-
return $mapper->map($data);
57+
return $mapper->map($data, $output);
5858
}
5959

6060
/**
6161
* Get the mapper for the given options.
6262
*/
6363
protected function getMapper(
64-
mixed $data,
6564
string $blueprintClass,
6665
TypeInterface $from,
6766
TypeInterface $to,

src/Mapper/Application/Service/Modificator.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PBaszak\UltraMapper\Blueprint\Application\Model\Blueprint;
88
use PBaszak\UltraMapper\Mapper\Application\Contract\ModificatorInterface;
99
use PBaszak\UltraMapper\Mapper\Application\Contract\ModifierInterface;
10+
use PBaszak\UltraMapper\Mapper\Domain\Model\Process;
1011

1112
class Modificator implements ModificatorInterface
1213
{
@@ -21,7 +22,7 @@ public function getModifiers(): array
2122
return $this->modifiers;
2223
}
2324

24-
public function prepareBlueprint(Blueprint $blueprint, string $processType, string $processUse): void
25+
public function prepareBlueprint(Blueprint $blueprint, Process $processType, string $processUse): void
2526
{
2627
foreach ($this->modifiers as $modifier) {
2728
// $modifier->prepareBlueprints();

src/Mapper/Domain/Contract/ClassMapperInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88

99
interface ClassMapperInterface
1010
{
11-
public function map(mixed $data): Envelope;
11+
public function map(mixed $data, mixed &$output = null): Envelope;
1212
}

src/Mapper/Domain/Contract/MatcherInterface.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,15 @@
66

77
use PBaszak\UltraMapper\Blueprint\Application\Model\Blueprint;
88
use PBaszak\UltraMapper\Mapper\Application\Contract\MapperInterface;
9+
use PBaszak\UltraMapper\Mapper\Domain\Model\Process;
910

1011
interface MatcherInterface
1112
{
1213
public const OPTION_ID = 'id';
1314
public const OPTION_PATH = 'path';
14-
public const OPTION_MIRROR = 'mirror';
1515
public const OPTION_ORIGIN = MapperInterface::BLUEPRINT_PROCESS_USE;
1616
public const OPTION_SOURCE = MapperInterface::FROM_PROCESS_USE;
1717
public const OPTION_TARGET = MapperInterface::TO_PROCESS_USE;
1818

19-
/**
20-
* @param string<"normalization"|"denormalization"|"transformation"|"mapping"> $processType
21-
*/
22-
public function matchBlueprints(string $processType, Blueprint $origin, Blueprint $source, Blueprint $target): void;
19+
public function matchBlueprints(Process $processType, Blueprint $origin, Blueprint $source, Blueprint $target): void;
2320
}

0 commit comments

Comments
 (0)