Is it possible to have fully custom dynamic Doctrine objects?
Doctrine generates proxy classes for your objects. This means that the doctrine generates PHP code with a class that extends your Entity class and redefines methods - puts some kind of user logic, and then calls the parent method.
So, I think the only way to do this really is to create PHP code for entities in your code. That is, every time an object is created on your website, you must generate a PHP file with this object, and then perform the migration.
Am I on the right track with my approach? If not, can you suggest an alternative?
I donโt think you should use Doctrine ORM at all in this case, at least the way you are trying to do it.
Typically, ORM is used to simplify / more manage programming. That is, you can establish relationships, use lazy loading, a unit of work (change the properties of an object, and then just hide it), etc. If your entities are dynamically generated, what functions will you use at all? The developer will not write code for these objects, because, as you said, there is no way to find out which fields he will have.
You have not provided a specific use case - why do you want to do this in the first place. But I believe that this could be done in a simpler way.
If users can store any structure at all, should MySQL be used at all? In such cases, ElasticSearch or similar solutions can be much better.
How do I get the really dynamic properties of a class? Or should I generate new Doctrine PHP object classes every time users change the configuration of an entity?
As I said, yes. If you do not want to redefine or replace any Doctrine code, but I think it can be a lot (proxy classes, etc.).
Marius balฤytis
source share