teamneusta / converter-bundle

An Open Source implementation of the Converter & Populator pattern
MIT License
5 stars 4 forks source link

`'$this'` as `$sourcePropertyName` means complete source object #60

Closed mike4git closed 4 months ago

mike4git commented 1 year ago

As mentioned in the issue: Sometimes you want to populate the complete (source) object in a certain target attribute/property. With that PR it is quite simple possible.

Closes #58

jdreesen commented 1 year ago

This PR would also mean, that with the following config:

# config/packages/neusta_converter.yaml
neusta_converter:
  converter:
    person.converter:
      # ...
      properties:
        email: ~
        phone: ''

the email would be populated from the target field email to the source field email while the for phone, the source object would be populated into the target field phone.

Would that be correct, and is this what we want?

I'd rather suggest that both ~ and '' should do the same here. What do you think?

mike4git commented 1 year ago

This PR would also mean, that with the following config:

# config/packages/neusta_converter.yaml
neusta_converter:
  converter:
    person.converter:
      # ...
      properties:
        email: ~
        phone: ''

the email would be populated from the target field email to the source field email while the for phone, the source object would be populated into the target field phone.

Would that be correct, and is this what we want?

I'd rather suggest that both ~ and '' should do the same here. What do you think?

I see your point but for some circumstances it is necessary that the "complete" source object should be populated into a certain target property. Should we write a new config for that?

What about a certain Populator type?!

jdreesen commented 1 year ago

I see your point but for some circumstances it is necessary that the "complete" source object should be populated into a certain target property.

But do you need it at this place? If I understood correctly, you wanted to use this especially together with the ConvertingPopulator?

mike4git commented 7 months ago

What would you think about the following syntax:

# config/packages/neusta_converter.yaml
neusta_converter:
  converter:
    person.converter:
      # ...
      properties:
        email: ~
        phone: this

So, as you mentioned:

The complete source object will be converted into phone target property.

jdreesen commented 7 months ago

I really like this idea!

But I would suggest using $this as the keyword. Then it is easier to recognize that it is not a normal field name.