Skip to content

Conversation

joelwurtz
Copy link
Member

@joelwurtz joelwurtz commented Apr 2, 2025

This allow automatically provide an entity from database instead of creating a new one, which will update values instead of generating a new entity

This is rather a first simple implementation, but it should work for the 90% use case

@joelwurtz joelwurtz marked this pull request as ready for review August 4, 2025 09:23
@joelwurtz joelwurtz requested a review from Korbeil August 4, 2025 09:32
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 think it's nice to base mapping on Doctrine metadata factory.
I would like to see something like an attribute / context thing to say "this is a Doctrine entity but I don't want to use entity manager just map it normally".
Also I think it would be nice to have extension points, at the moment it is very rigid and we can't do much to extends it (mostly Doctrine provider in my opinion).

* @return object|array<mixed>|null the value to provide
*/
public function provide(string $targetType, mixed $source, array $context): object|array|null;
public function provide(string $targetType, mixed $source, array $context, /* mixed $id */): object|array|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 use context for this identifier ? Instead of modifying all the providers for only one provider ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the id is a major information that require its own variable. Futhermore, i think this id can be used by user provider so it's nice to have it here.

I really don't like putting that kind of information into the context

Copy link
Collaborator

@nikophil nikophil left a comment

Choose a reason for hiding this comment

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

really nice feature 👍

WDYT of also supporting doctrine Mongo ODM?

since you're mainly relying on ClassMetadataFactory which is an abstraction from doctrine/persistence it should not require too much effort

I would like to see something like an attribute / context thing to say "this is a Doctrine entity but I don't want to use entity manager just map it normally".

💯

@joelwurtz
Copy link
Member Author

WDYT of also supporting doctrine Mongo ODM?

I updated the PR it should support the odm document manager, there is no configuration to tell which manager to use, but it's only an alias to set for the user in their service, don't want to go further, let's wait to se on how it's used

@joelwurtz
Copy link
Member Author

I would like to see something like an attribute / context thing to say "this is a Doctrine entity but I don't want to use entity manager just map it normally

I added the possibility to do :

#[MapProvider(provider: false)]

Which will disable any provider discovered

Also I think it would be nice to have extension points, at the moment it is very rigid and we can't do much to extends it (mostly Doctrine provider in my opinion).

Don't think it should be done in this PR, let's wait for usage before doing that

@joelwurtz joelwurtz requested a review from Korbeil September 2, 2025 08:12
@joelwurtz
Copy link
Member Author

I will merge this (but no release yet), will try this on a real project to see what if gives

@joelwurtz joelwurtz merged commit 7383d7c into main Sep 4, 2025
6 checks passed
@joelwurtz joelwurtz deleted the feat/doctrine branch September 4, 2025 07:02
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.

3 participants