Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mapper): allow to merge existing values by extracting identifiers #260

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

joelwurtz
Copy link
Member

This introduce the possibility to deep merge object with collections and fetching the correct value to update it instead of adding a new one into the collection

@joelwurtz joelwurtz force-pushed the feat/merge-existing-value-with-identifier branch from f57c1f9 to d33b20f Compare April 6, 2025 10:55
@joelwurtz joelwurtz force-pushed the feat/merge-existing-value-with-identifier branch from 171675c to 0979712 Compare April 6, 2025 17:22
@joelwurtz joelwurtz force-pushed the feat/merge-existing-value-with-identifier branch from 745cb5b to 12a3e45 Compare April 6, 2025 17:26
@joelwurtz joelwurtz requested a review from Korbeil April 6, 2025 21:02
Copy link
Member

@Korbeil Korbeil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think it adds a lot of complexity to Array transformers (from/to), would it be possible to add some kind of abstraction to separate the pure mapping part & the identifier/existing values handling in separate class / traits or whatever ?

private readonly string $property,
private readonly bool $private = false,
public readonly string $property,
public readonly bool $private = false,
public readonly ?\ReflectionParameter $parameter = null,
private readonly ?string $removeMethodName = null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we pass this as public as well ? Since it's readonly there is no point letting it alone as private.

$itemStatements[] = new Stmt\Expression(new Expr\Assign($mappedValueVar, $output));
$itemStatements[] = new Stmt\If_(new Expr\BinaryOp\NotIdentical(new Expr\ConstFetch(new Name('null')), $mappedValueVar), [
'stmts' => [
new Stmt\Expression($propertyMapping->target->writeMutator->getExpression($target, $mappedValueVar, $assignByRef)),
],
]);

// @TODO handle existingValue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants