开发者

How do you work with User entity and its connection status?

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 us开发者_开发知识库e 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.


You're right to think about some kind of service, separate from your User entity, to manage this stuff. The entity shouldn't know about data access, etc.

Have a look at Zend_Auth. You'll want to create Zend_Auth_Adapter to work with Doctrine2. A little googling turned up this example, which might be instructive. Zend_Auth is nice and simple, and works nicely with the Zend_Acl stuff for managing authorization, once you have authenticated your users.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜