Doctrine User Entity in Symfony: knowing the location of the avatar
Let's say I have a Doctrine User Entity. Every user has an avatar and there's of course a specific folder on the webserver where these avatars reside. My question is: should the User Entity know this location?
I'm currently storing the avatar folder URL as a parameter in Symfony2. I'm injecting this parameter into Twig so that Twig can print the correct URL. I considered also injecting the parameter into the User Entity, e.g. for when a user is removed and I'd like to let the Entity remove the avatar image. However different sources mention that Doctrine Entity's are mere POPO's (Plain Old PHP Object) and that it's bad practice to inject anything into them.
This suggests that the answer to my question is 'No'. Which raises a new question: where should the User deletion business logic reside? And how does this know the location of the avatar?
I think you could use a UserManager service where all this business logic would be located.
The shorter solution is to set the path in the User entity and do your logic there as you don't need any external service to save/delete the user avatar file, as seen here : http://symfony.com/doc/master/cookbook/doctrine/file_uploads.html