I'm currently working on a project with Zend Framework & Doctrine 2, I'm really happy with both of those tools, but I'm wondering on how work with this special User object, which shares database data, session data (authorization, paramaters, acl, etc..)
I often see this kind of implemtation :
if (User::isConnected())
The problem for me is that my User class, is an entity which is used by Doctrine, well it's not a problem, but it may add some business logic if my User has some complex role and/or privileges.
By the way, I don't know why (just a feeling, maybe wrong) but it doesn't look like a good idea, I'm pretty sure it has design limits.
Currently my idea, is to use a UserService, I already try to use such layer for my other entity and it looks really interesting.
What about something like :
$service = new UserService($entityManager);
if ($service->isUserConnected($user))
It may let me use another service, like IdentificationService which may stores "user" (or any other "resource" which may be authorized) into session and check for authorization.
The same could apply to AuthorizationService with method like :
$service->isAuthorized($user, $resource, $action)
Do you have any feedback on this kind of implementation? And/or any examples?
What are your thoughts?
Thank you.