@@ -343,15 +343,16 @@ target class can be mapped from multiple source classes::
343343 use App\Api\ExternalProduct;
344344 use App\Dto\InternalProduct;
345345 use Symfony\Component\ObjectMapper\Attribute\Map;
346+ use Symfony\Component\ObjectMapper\Condition\SourceClass;
346347
347348 #[Map(source: ExternalProduct::class)]
348349 #[Map(source: InternalProduct::class)]
349350 class Product
350351 {
351352 // map from 'externalName' only when the source is ExternalProduct
352- #[Map(source: 'externalName', if: new \Symfony\Component\ObjectMapper\Condition\ SourceClass(ExternalProduct::class))]
353+ #[Map(source: 'externalName', if: new SourceClass(ExternalProduct::class))]
353354 // map from 'name' only when the source is InternalProduct
354- #[Map(source: 'name', if: new \Symfony\Component\ObjectMapper\Condition\ SourceClass(InternalProduct::class))]
355+ #[Map(source: 'name', if: new SourceClass(InternalProduct::class))]
355356 public string $name = '';
356357 }
357358
@@ -367,13 +368,14 @@ when the object is an instance of any of them. This reduces the number of
367368``#[Map] `` attributes needed for multi-class mappings::
368369
369370 use Symfony\Component\ObjectMapper\Attribute\Map;
371+ use Symfony\Component\ObjectMapper\Condition\SourceClass;
370372
371373 #[Map(source: B::class)]
372374 #[Map(source: C::class)]
373375 class A
374376 {
375377 // applies when the source is either B or C
376- #[Map(source: 'foo', if: new \Symfony\Component\ObjectMapper\Condition\ SourceClass([B::class, C::class]))]
378+ #[Map(source: 'foo', if: new SourceClass([B::class, C::class]))]
377379 public string $something = '';
378380 }
379381
@@ -391,6 +393,9 @@ checks in a single condition, and
391393when any of its rules matches::
392394
393395 use Symfony\Component\ObjectMapper\Attribute\Map;
396+ use Symfony\Component\ObjectMapper\Condition\ClassRule;
397+ use Symfony\Component\ObjectMapper\Condition\ClassRuleList;
398+ use Symfony\Component\ObjectMapper\Condition\SourceClass;
394399 use Symfony\Component\ObjectMapper\Condition\TargetClass;
395400
396401 #[Map(source: B::class)]
@@ -400,15 +405,15 @@ when any of its rules matches::
400405 class A
401406 {
402407 // when reading from a source: apply only when source is B
403- #[Map(source: 'foo', transform: 'strtolower', if: new \Symfony\Component\ObjectMapper\Condition\ ClassRuleList([new \Symfony\Component\ObjectMapper\Condition\ SourceClass(B::class)]))]
408+ #[Map(source: 'foo', transform: 'strtolower', if: new ClassRuleList([new SourceClass(B::class)]))]
404409 // when reading from a source: apply only when source is C
405- #[Map(source: 'bar', if: new \Symfony\Component\ObjectMapper\Condition\ ClassRuleList([new \Symfony\Component\ObjectMapper\Condition\ ClassRule(sources: [C::class])]))]
410+ #[Map(source: 'bar', if: new ClassRuleList([new ClassRule(sources: [C::class])]))]
406411 public string $somethingSourced = '';
407412
408413 // when writing to a target: apply only when target is B
409- #[Map(target: 'foo', transform: 'strtoupper', if: new \Symfony\Component\ObjectMapper\Condition\ ClassRuleList([new TargetClass(B::class)]))]
414+ #[Map(target: 'foo', transform: 'strtoupper', if: new ClassRuleList([new TargetClass(B::class)]))]
410415 // when writing to a target: apply only when target is C
411- #[Map(target: 'bar', if: new \Symfony\Component\ObjectMapper\Condition\ ClassRuleList([new \Symfony\Component\ObjectMapper\Condition\ ClassRule(targets: [C::class])]))]
416+ #[Map(target: 'bar', if: new ClassRuleList([new ClassRule(targets: [C::class])]))]
412417 public string $somethingTargeted = '';
413418 }
414419
0 commit comments