Skip to content

Commit 907dd25

Browse files
added earlier skip to allow if=false when using source mapping
1 parent 9ec163b commit 907dd25

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/Symfony/Component/ObjectMapper/ObjectMapper.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,13 @@ public function map(object $source, object|string|null $target = null): object
122122
$sourcePropertyName = $mapping->source;
123123
}
124124

125-
$value = $this->getRawValue($source, $sourcePropertyName);
126-
if (($if = $mapping->if) && ($fn = $this->getCallable($if, $this->conditionCallableLocator)) && !$this->call($fn, $value, $source, $mappedTarget)) {
125+
$if = $mapping->if;
126+
if(false === $if) {
127127
continue;
128128
}
129129

130-
if (false === $if) {
130+
$value = $this->getRawValue($source, $sourcePropertyName);
131+
if ($if && ($fn = $this->getCallable($if, $this->conditionCallableLocator)) && !$this->call($fn, $value, $source, $mappedTarget)) {
131132
continue;
132133
}
133134

src/Symfony/Component/ObjectMapper/Tests/Fixtures/HydrateObject/SourceOnly.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
class SourceOnly
1717
{
18-
public function __construct(#[Map(source: 'name')] public string $mappedName)
19-
{
18+
public function __construct(
19+
#[Map(source: 'name')] public string $mappedName,
20+
#[Map(if: false)] public ?string $mappedDescription = null
21+
) {
2022
}
2123
}

0 commit comments

Comments
 (0)