@@ -69,10 +69,15 @@ public function transform(Expr $input, Expr $target, PropertyMetadata $propertyM
69
69
);
70
70
71
71
if ($ propertyMapping ->target ->readAccessor !== null && $ this ->itemTransformer instanceof IdentifierHashInterface) {
72
+ $ targetHashVar = new Expr \Variable ($ uniqueVariableScope ->getUniqueName ('targetHash ' ));
73
+
72
74
$ loopExistingStatements [] = new Stmt \If_ ($ isDeepPopulateExpr , [
73
75
'stmts ' => [
74
- new Stmt \Expression (new Expr \Assign (new Expr \ArrayDimFetch ($ exisingValuesIndexed , $ this ->itemTransformer ->getTargetHashExpression ($ loopRemoveValueVar )), $ loopRemoveValueVar )),
75
- ],
76
+ new Stmt \Expression (new Expr \Assign ($ targetHashVar , $ this ->itemTransformer ->getTargetHashExpression ($ loopRemoveValueVar ))),
77
+ new Stmt \If_ (new Expr \BinaryOp \NotIdentical (new Expr \ConstFetch (new Name ('null ' )), $ targetHashVar ), [
78
+ 'stmts ' => [new Stmt \Expression (new Expr \Assign (new Expr \ArrayDimFetch ($ exisingValuesIndexed , $ targetHashVar ), $ loopRemoveValueVar ))],
79
+ ]),
80
+ ],
76
81
]);
77
82
}
78
83
@@ -96,17 +101,24 @@ public function transform(Expr $input, Expr $target, PropertyMetadata $propertyM
96
101
new Stmt \Expression ($ propertyMapping ->target ->writeMutator ->getExpression ($ target , $ mappedValueVar , $ assignByRef )),
97
102
],
98
103
]);
99
-
100
- // @TODO handle existingValue
101
104
} else {
102
105
$ loopExistingValueVar = new Expr \Variable ($ uniqueVariableScope ->getUniqueName ('existingValue ' ));
103
106
104
107
if ($ propertyMapping ->target ->readAccessor !== null && $ this ->itemTransformer instanceof IdentifierHashInterface) {
105
108
$ hashValueVariable = new Expr \Variable ($ uniqueVariableScope ->getUniqueName ('hashValue ' ));
106
- $ statements [] = new Stmt \If_ (new Expr \BinaryOp \Coalesce (
109
+
110
+ $ isDeepPopulateExpr = new Expr \BinaryOp \Coalesce (
107
111
new Expr \ArrayDimFetch (new Expr \Variable ('context ' ), new Scalar \String_ (MapperContext::DEEP_TARGET_TO_POPULATE )),
108
112
new Expr \ConstFetch (new Name ('false ' ))
109
- ), [
113
+ );
114
+
115
+ $ isDefinedExpr = $ propertyMapping ->target ->readAccessor ->getIsDefinedExpression (new Expr \Variable ('result ' ));
116
+
117
+ if ($ isDefinedExpr !== null ) {
118
+ $ isDeepPopulateExpr = new Expr \BinaryOp \BooleanAnd ($ isDeepPopulateExpr , $ isDefinedExpr );
119
+ }
120
+
121
+ $ statements [] = new Stmt \If_ ($ isDeepPopulateExpr , [
110
122
'stmts ' => [
111
123
new Stmt \Foreach_ ($ propertyMapping ->target ->readAccessor ->getExpression ($ target ), $ loopExistingValueVar , [
112
124
'stmts ' => [
0 commit comments