Implemented an ObjectPersisterInterface for entity/object storage#317
Implemented an ObjectPersisterInterface for entity/object storage#317linaori wants to merge 2 commits intodoctrine:masterfrom linaori:master
Conversation
|
Hello, thank you for creating this pull request. I have automatically opened an issue http://www.doctrine-project.org/jira/browse/DCOM-235 We use Jira to track the state of pull requests and the versions they got |
Wrong extend
|
👍 |
1 similar comment
|
👍 |
|
You can use composition to hide the the EntityManager. I don't think this is really necessary to have in Doctrine core, because it doesnt add much benefit. Its much better you provide your own interface, wrap the EntityManager and then have something with a much better name. |
|
@beberlei I still think that the interface being splitted in common allows for more granular reuse from all those packages that directly depend on Re-defining a persister interface in sub-packages can obviously be done, but why not having a persister that does not handle finder logic? For example, a queue where to push objects to be "saved" (don't know what it does, internally) will never be able to implement the I'm fine with having such an interface in my own package, but having it here would do no harm either IMO. |
|
@beberlei, Its part of Doctrine, Doctrine is lacking a proper interface to actually store things. You are always forced to directly program on the EntityManager like this. If so, then why even bother hiding it in the repository? I can't interface this myself, it would be used on too many of our bundles/projects. Making a composer package for 1 interface is a no-go too. If not like this, then how are people supposed to properly flush without having the EntityManager flying around everywhere? I know for sure that if I pass the EntityManagerInterface around, people will start using calls at places they shouldn't. I don't want to depent on the world if I need 2 methods. There is animo for this PR, so why instantly close it? |
|
Given that a core team member thinks this kinda makes sense, can this please be reconsidered? Having to create an interface doing this in all packages seems strange... |
|
@wouterj looked at it again, and I don't think we should re-evaluate this before having a plan for new APIs (3.x). For now, composition is enough. |
Why is this useful?
Instead of using the
repositoryClass, we use 'Repository as a Service'. This means that we inject our repository service instead of doing$em->getRepository('MyEntity'), this provides typehinting and autocomplete in IDEs. This introduces a minor inconvenience, we need to inject anEntityManagerInterfaceto provide persist/flush. We don't want the entireEntityManagerInterfacecapabilities just to store an object.Using the
ObjectPersisterInterfacewe can "hide" theEntityManagerInterfaceand only let the code know we have the persist and flush methods available. By default this is implemented on theEntityManager, but is also possible to be mocked or replaced by a custom implementation (rotating entity managers?).Example