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

AbstractCommand - assert accept only instanceof EntityManager #8488

Closed
martinolmr opened this issue Feb 18, 2021 · 5 comments · Fixed by #8493
Closed

AbstractCommand - assert accept only instanceof EntityManager #8488

martinolmr opened this issue Feb 18, 2021 · 5 comments · Fixed by #8493
Assignees
Milestone

Comments

@martinolmr
Copy link

AbstractCommand, line 56

Accept only EntityManager instances:

assert($em instanceof EntityManager);

Should be:

assert($em instanceof EntityManagerInterface);
@acelaya
Copy link
Sponsor

acelaya commented Feb 20, 2021

Same here. Looks like this happens since v2.8.2, as v2.8.1 doesn't throw Fatal error: Uncaught AssertionError: assert($em instanceof EntityManager).

greg0ire added a commit to greg0ire/doctrine-orm that referenced this issue Feb 20, 2021
EntityManager is too restrictive, any implementation can actually be
returned here.

Closes doctrine#8488
greg0ire added a commit to greg0ire/doctrine-orm that referenced this issue Feb 20, 2021
EntityManager is too restrictive, any implementation can actually be
returned here.

Closes doctrine#8488
greg0ire added a commit to greg0ire/doctrine-orm that referenced this issue Feb 20, 2021
EntityManager is too restrictive, any implementation can actually be
returned here.

Closes doctrine#8488
beberlei pushed a commit that referenced this issue Feb 21, 2021
EntityManager is too restrictive, any implementation can actually be
returned here.

Closes #8488
@beberlei beberlei added this to the 2.8.3 milestone Feb 21, 2021
@greg0ire
Copy link
Member

Out of curiosity, what is used there if not EntityManager? Some decorator?

@acelaya
Copy link
Sponsor

acelaya commented Feb 21, 2021

In my case yes, a decorator. It extends from this https://github.com/doctrine/orm/blob/2.8.x/lib/Doctrine/ORM/Decorator/EntityManagerDecorator.php

@beberlei
Copy link
Member

@acelaya what is the decorators purpose? Can you explain?

@acelaya
Copy link
Sponsor

acelaya commented Feb 21, 2021

Sure!

I serve my application with swoole. Since it keeps services in memory to reuse them on subsequent requests, it can happen that the EntityManager has been closed for some reason, or the connection with the database has expired.

What my decorator does is allow to transparently recreate the wrapped EntityManager if needed.

To simplify things, I do this by exposing an open method which is called by a PSR-15 middleware, which also makes sure to close the DB connection and clear the EntityManager to avoid memory leaks or mixing units of work.

The project is open source, so you can see the code here:

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

Successfully merging a pull request may close this issue.

4 participants