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

[PropertyMappingPopulator] Make null safety possible #68

Closed
mike4git opened this issue Mar 18, 2024 · 3 comments · Fixed by #69
Closed

[PropertyMappingPopulator] Make null safety possible #68

mike4git opened this issue Mar 18, 2024 · 3 comments · Fixed by #69

Comments

@mike4git
Copy link
Collaborator

The PropertyMappingPopulator should be able to be configured that in case the source property value is null either accessor should be called or accessor should not be called (null safety).
Therefore it is recommended, that a new property $nullSafety of type bool will be introduced called nullSafety (by default: false - cause this is the current default behaviour).

@jdreesen
Copy link
Member

What's the problem with reading null values?

@mike4git
Copy link
Collaborator Author

The reading of null values is no problem but sometimes you don't want to set in case of a null value.
Imagine your target object should NOT be overwritten in case of null. How to handle?

@mike4git
Copy link
Collaborator Author

We have in our project context the following situation:

        if (null !== $shopAddress->getSalutation()) {
            $apiAddress->setSalutation($shopAddress->getSalutation());
        }
        if (null !== $shopAddress->getFirstname()) {
            $apiAddress->setFirstname($shopAddress->getFirstname());
        }
        if (null !== $shopAddress->getLastname()) {
            $apiAddress->setLastname($shopAddress->getLastname());
        }
        if (null !== $shopAddress->getCompany()) {
            $apiAddress->setCompany($shopAddress->getCompany());
        }
...
 

You can not use the PropertyMappingPopulator here. Otherwise you would set target properties to null.

mike4git added a commit that referenced this issue Mar 18, 2024
…pulator

add test for dot operator
add debug functionality to php docker container for testing
@mike4git mike4git linked a pull request Mar 18, 2024 that will close this issue
mike4git added a commit that referenced this issue Mar 18, 2024
add test for Extension class
mike4git added a commit that referenced this issue Apr 2, 2024
…pulator

add test for dot operator
add debug functionality to php docker container for testing
mike4git added a commit that referenced this issue Apr 2, 2024
add test for Extension class
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 a pull request may close this issue.

2 participants