Skip to content

Commit df881cc

Browse files
committed
feature #60028 [ObjectMapper] Condition to target a specific class (soyuka)
This PR was squashed before being merged into the 7.3 branch. Discussion ---------- [ObjectMapper] Condition to target a specific class | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | License | MIT We want to be able to choose which property to map according to the target. Here `foo` is mapped to `B` only when the target is `B`. If `C` has a `foo` property it won't be mapped as we only map to `bar`. ```php use Symfony\Component\ObjectMapper\Attribute\Map; use Symfony\Component\ObjectMapper\TargetClass; #[Map(target: B::class)] #[Map(target: C::class)] class A { #[Map(target: 'foo', transform: 'strtoupper', if: new TargetClass(B::class))] #[Map(target: 'bar')] public string $something = 'test'; public string $doesNotExistInTargetB = 'foo'; } ``` This is a good alternative to groups as we can have one class that has multiple representation. Commits ------- a5698aaf88f [ObjectMapper] Condition to target a specific class
2 parents 62040cf + 5b3a4cf commit df881cc

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Tests/Fixtures/ObjectMapper/TransformCallable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
final class TransformCallable implements TransformCallableInterface
2020
{
21-
public function __invoke(mixed $value, object $object): mixed
21+
public function __invoke(mixed $value, object $source, ?object $target): mixed
2222
{
2323
return 'transformed';
2424
}

0 commit comments

Comments
 (0)