Skip to content

Conversation

@soyuka
Copy link
Contributor

@soyuka soyuka commented Oct 26, 2025

Q A
Branch? 7.4
Bug fix? yes
New feature? yes
Deprecations? no
Issues Fixes #61357
License MIT

See changelog and related issue:

  • Add a DepthAwareInterface to gather information about the mapping depth
  • Add a TransformAllProperties that applies a transform on all properties of
    a mapped object
  • Add a UninitializeProxy transform that skips proxy initialization for a
    given depth

@nicolas-grekas
Copy link
Member

The CI needs some love ;)

@soyuka soyuka force-pushed the transform-all-props branch from a4d279b to 5467844 Compare October 26, 2025 20:04
@soyuka soyuka force-pushed the transform-all-props branch from 5467844 to 32cc430 Compare October 26, 2025 20:06
@soyuka
Copy link
Contributor Author

soyuka commented Oct 26, 2025

It got the love it deserved :).

@Coffee2CodeNL
Copy link
Contributor

Coffee2CodeNL commented Oct 27, 2025

  1. What if I want to combine a Collection Transformer (for instance, a Doctrine ArrayCollection into an array of mapped DTOs, in my specific case, API Resources for API Platform) with the 'all properties' UninitializeProxy?

  2. Isn't it better to add a depth option to the transformer call itself on a property where we know recursion occurs, like a doctrine relationship, instead of adding a transformer that acts upon all properties? Maybe something like #[Mapper\MaxDepth(int)?

  3. Wouldn't it be easier to do this if you split the creation of a target object (and maybe conditionally instantiate a single property, like an ID field of an entity on the target DTO) and the population of a target object (the rest of the properties)? Could a #[Mapper\InitializeProperty] attribute be useful for that?

@soyuka
Copy link
Contributor Author

soyuka commented Oct 27, 2025

  1. What if I want to combine a Collection Transformer (for instance, a Doctrine ArrayCollection into an array of mapped DTOs, in my specific case, API Resources for API Platform) with the 'all properties' UninitializeProxy?

As the collection transformer just calls ->map on every item, for each of these items if they've an uninitialize proxy it's working like this already.

  1. Isn't it better to add a depth option to the transformer call itself on a property where we know recursion occurs, like a doctrine relationship, instead of adding a transformer that acts upon all properties? Maybe something like #[Mapper\MaxDepth(int)?

It's really weird that recursion occurs as we track recursive objects therefore this should not happen. This PR indeed allows to create a IfDepth(3) condition that would prevent any field of mapping after a given depth.

  1. Wouldn't it be easier to do this if you split the creation of a target object (and maybe conditionally instantiate a single property, like an ID field of an entity on the target DTO) and the population of a target object (the rest of the properties)? Could a #[Mapper\InitializeProperty] attribute be useful for that?

Exactly and you can already do this, actually this should probably be done for example in API Platform when a property is not readableLink: true. This is already possible but should probably be fixed in the usage of ObjectMapper (as opposed to modifying the symfony component). Not sure to understand #[Mapper\InitializeProperty].

@soyuka
Copy link
Contributor Author

soyuka commented Oct 29, 2025

superseeded by #62214

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ObjectMapper] Multiple: context array, mapping depth, selective instantiation of lazy objects.

4 participants