You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
0 commit comments