Can we have a model class which is singleton in Doctrine?
For Singleton classes I should have a private/protected constructor….but this is not possible as I am extending a Doctrine class which has a public constructor
You can argue about the use of the Singleton pattern when interacting with the DB, but just consider this scenario:
I have a user action logger which logs to the database. This logger does some initialization
in the constructor (getting the current users information from the session) which is common
for all instances of the logger for a particular execution.
There seems to be no way to implement the singleton pattern for models when using Doctrine?
An instance of a Doctrine model class corresponds to one entity, e.g. an instance of
Userrepresents one user, and I doubt you have only one of those.Put your other code in a separate class,
UserManageror something.