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

Use EntityManagerInterface in type declarations #9325

Merged
merged 1 commit into from
Jan 12, 2022

Conversation

derrabus
Copy link
Member

@derrabus derrabus commented Jan 3, 2022

The codebase inconsitently switched between EntityManagerInterface and EntityManager in type declarations. This will get us into trouble if we want to migrate to native type declarations on 3.0.

This PR switches all type declarations to EntityManagerInterface where possible.

@greg0ire
Copy link
Member

greg0ire commented Jan 3, 2022

I think @beberlei had a plan to kill that interface, not sure if this is the right move but I think he needs to review this.

@derrabus
Copy link
Member Author

derrabus commented Jan 9, 2022

@beberlei Do you have input on that topic?

@beberlei
Copy link
Member

beberlei commented Jan 9, 2022

We introduced the interface to help with the use of EntityManagerDecorator, since we didn't want people to extend the EntityManager and its marked as "soft final".

The problem is in a decoration, code like new UnitOfWork($this) or $this->repositoryFactory->getRepository($this, $entityName); does not pass the decorator, but the decoratee / original.

Its a hard problem, it seems some people want to extend/decorate the EM for whatever reason, but its not a good solution for us. We could just give up and recommend extending EntityManager instead to simplify the problem for us. A lot of time has been wasted into this interface already.

@derrabus
Copy link
Member Author

derrabus commented Jan 9, 2022

So your plan would be to get rid of the interface (and consequently the abstract decorator) completely? That would generate the harder migration path for applications. Especially in Symfony applications, it is common to type-hint EntityManagerInterface if write a service that depends on the entity manager. Also, the interface is quite handy if you want to write mock implementations of the EM.

I agree that decorating the entity manager is not really a good way of extending the ORM. But at this point, I'd keep the interface tbh.

Copy link
Member

@beberlei beberlei left a comment

Choose a reason for hiding this comment

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

Probably a wishful thinking of me, but yeah it would have been nice. But you are right, we should just go with the interface now. 👍 from me then. One question, i would remove the trait and inline the code into AbstractIdGenerator, unless I am not seeing something.

lib/Doctrine/ORM/Id/LegacyIdGeneratorProxy.php Outdated Show resolved Hide resolved
@derrabus derrabus force-pushed the improvement/em-interface branch 2 times, most recently from 2d4827c to 23f30ea Compare January 11, 2022 10:01
beberlei
beberlei previously approved these changes Jan 12, 2022
@derrabus derrabus merged commit ee59119 into doctrine:2.11.x Jan 12, 2022
@derrabus derrabus deleted the improvement/em-interface branch January 12, 2022 10:00
derrabus added a commit to derrabus/orm that referenced this pull request Jan 12, 2022
* 2.11.x:
  Use EntityManagerInterface in type declarations (doctrine#9325)
  Add errors caused by the lexer update to the baselines (doctrine#9360)
  Generated/Virtual Columns: Insertable / Updateable (doctrine#9118)
  Remove the composer/package-versions-deprecated package
  Relax assertion to include null as possible outcome (doctrine#9355)
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.

3 participants