core icon indicating copy to clipboard operation
core copied to clipboard

feat(doctrine): new hook for entity/document transformation

Open mrossard opened this issue 10 months ago • 3 comments

Q A
Branch? main
License MIT
Doc PR TODO

Currently when using stateOptions to specify the entityClass (or documentClass) for your custom ApiResource, the standard StateProviders do exactly what you need most of the time, but you still often need to write custom providers to correctly map the entity/document to the actual resource.

This adds the possibility to specify a hook (the same way you specify custom a handleLinks method) to transform the doctrine entity or document into the desired ApiResource without having to write a full custom StateProvider.

mrossard avatar Jan 15 '25 11:01 mrossard

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Mar 22 '25 19:03 stale[bot]

just a comment to stop this from closing, trying to find the time to complete this.

mrossard avatar Mar 23 '25 08:03 mrossard

sorry my bad :)

soyuka avatar Mar 25 '25 09:03 soyuka

At long last I found some time to revisit this PR. @soyuka what do you think ?

I haven't looked at how it fits in with https://github.com/api-platform/core/pull/6801 yet, but i guess that would be a default implementation of the ResourceTransformerInterface using the Mapper symfony extension if it's available.

mrossard avatar Jul 24 '25 08:07 mrossard

My question is more: doesn't object mapper already does the transformation hook ? I'm not sure we need a transformation hook when using the object mapper. If you mark a class with the Map attribute it'll be transformed.

soyuka avatar Jul 24 '25 08:07 soyuka

My question is more: doesn't object mapper already does the transformation hook ? I'm not sure we need a transformation hook when using the object mapper. If you mark a class with the Map attribute it'll be transformed.

I haven't looked in depth at what ObjectMapper can do yet, and it's entirely possible what i was doing is now redundant.

Let me try to do what i had in mind with it, if it works as i hope i'll just close this PR.

mrossard avatar Jul 24 '25 09:07 mrossard

from what we discussed I think we can close this, let me know if its still relevant!

soyuka avatar Aug 18 '25 13:08 soyuka