I would like to have entities log the user (preferably his ID) that has most recently modified an entity. I think a pretty entity has a getModifier() method but has no setModifier() since that is handled by the class as an internal affair. I'd use some prePersist to update the entity with the user ID. So here are the two main questions:
1) Technically, how can I get the current user's ID inside an entity's prePersist?
2) Philosophy. I have found lots of answers that advise me to rethink my model not to be dependent on anything other than the data stored in it. I fail to see how the isolating entities from the rest of the world is sane: see two contrasts here on what is allowed for entities to do. Accessing a service to get a folder-name where some cached output can be stored is thought illegal; while writing to the filesystem with file abstraction classes is OK; I think the latter makes more assumptions about filesystems. Accessing the current user's identity is considered illegal; while putting current timestamps on the entity is OK; so the concept of a (possibly missing) user is bad while the concept of time is good? If the concept about not relying on anything other than the model itself is valid then how does anyone dare to use DateTime functions? (Please don't say that the services of PHP are always accessible, because some missing settings/extensions can easily cause these to fail.) I fail to see how to build any logic into entities while adhering to such strict restrictions, and how to avoid that entities end up to be nothing more than data (by this level of encapsulation and information hiding, this entity model offers me nothing over mere arrays). Could anyone point me what is the particular difference between those elements of the model's environment that must not be used and those that are considered legitim?