mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-3392: Add a way to use a custom instantiator in ClassMetadataInfo #4190
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Nov 13, 2014).
Originally assigned to: @Ocramius on GitHub.
Jira issue originally created by user rekam:
Hi,
In my project, I'm using a home made container of dependencies, that I use sometimes in my entities. I found very useful to use EntityListeners and EntityResolver to be able, on PostLoad event, to inject dependencies into the models.
Thinking of that, should it be a good idea to implement some custom instantiators that could do this, using the model's constructor?
Here's a quick example:
Now in ClassMetadataInfo class, the instantiator cannot be overridden. Check these lines below. Instantiator is private and created via [new] in constructor and in wakeup method. Do we need to override ClassMetadataInfo to achieve this?
Thanks,
@doctrinebot commented on GitHub (Nov 13, 2014):
Comment created by @ocramius:
This is exactly the type of dependency that you DO NOT want in an entity.
Don't do this, it's discouraged and it will likely cause only headaches.
Marking as
Won't Fix.@doctrinebot commented on GitHub (Nov 13, 2014):
Issue was closed with resolution "Won't Fix"
@doctrinebot commented on GitHub (Nov 13, 2014):
Comment created by rekam:
Thanks for your feedback. I'm playing with this design pattern since a few days only, so I'm not quite confident about what is or isn't "good".
So your approach is to add a listener to the entity and manage all dependencies in the listener class? Can we say that's a best practice, or even a rule, to not ask for any dependency in any method of any entity?
Have a nice evening
@doctrinebot commented on GitHub (Nov 13, 2014):
Comment created by @ocramius:
{quote}So your approach is to add a listener to the entity and manage all dependencies in the listener class?{quote}
The idea is to NOT have dependencies in entities at all. It is arguably not necessarily an absolute, but it's a good practice to let entities only be aware of their siblings.
See also http://misko.hevery.com/2008/09/30/to-new-or-not-to-new/