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

Allow ORM to use ResolveTargetEntityListener in ManagerRegistry::getManagerForClass() #149

Open
wants to merge 2 commits into
base: 2.1.x
Choose a base branch
from

Conversation

mpdude
Copy link
Contributor

@mpdude mpdude commented Dec 3, 2020

I am not quite sure if this is the right place to ask, because the change aims at a feature of ORM. Anyways, here it goes:

Doctrine ORM features a ResolveTargetEntityListener. This mechanism allows to use Interface names in various places, for example in Association Mappings or when querying Repositories from Entity Managers.

It would be helpful if the AbstractManagerRegistry could support looking up Managers by such interfaces as well.

The problem with the current implementation is that it makes use of the isTransient property. Probably this happens to speed up things: Inside the Metadata Factory, the Driver can determine isTransient() more easily, without loading the full metadata.

Interfaces, however, are (to my understanding) always transient, so getManagerForClass() never works for them. This is where this PR hopes to improve things without affecting performance for existing use cases.

Will add tests once I get basic approval and 👍s.

Background: ManagerRegistry::getManagerForClass() is used inside https://github.com/sensiolabs/SensioFrameworkExtraBundle for the Symfony Framework. So-called "ParamConverters" can automagically fetch (ORM) Entities for request parameters and pass those into Controller classes, reducing boilerplate code. It would be great if we could make this work as well for "resolved target entities".

@esmultivac
Copy link

I don't think this will work with more than one entity managers. Maybe something like this will work better:

        $metadataFactory = $manager->getMetadataFactory();

        if (! $metadataFactory->isTransient($class) || $metadataFactory->hasMetadataFor($class)) {
            return $manager;
        }

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.

None yet

2 participants