Symfony2 FOSUserBundle Role entities

柔情痞子 提交于 2019-11-30 03:11:03

问题


I'm currently trying to figure out the best way to implement doctrine persisted Role entities as a M2M relationship compatible with FOSUserBundle. Previously I was using just strings with the default implementation and was persisting it with a doctrine array mapping.

Now I need to have roles as seperate entites as we want to build an admin backend where others can grant users roles.

Basically, it's a pain in the ass. The FOS interfaces are built for string representations, not Role entities. Change the implementation, you break a lot of stuff i.e. FOS commands to promote users. And it's hard to figure out exactly which pieces of the interfaces are needed to allow the symfony2 security system to continue working correctly.

I could rewrite the role management code and use Role entities as much as possible, e.g.:

$user->addRole(new Role('ROLE_FOO'));

But that breaks commands and possibly existing code?

Or continue using:

$user->addRole('ROLE_FOO');

And couple role/entity manager code in addRole() (bad design).

I've noticed this is a grey area (Role entities with FOS) and has been mentioned on the symfony2 boards and round here, but no decent solutions.

Anyone had any experience or can think of a decent solution?


回答1:


I decided to go with a mix of an array/ArrayCollection implementation. I tried to follow the existing interfaces as much as possible so as not to break the security system. I have documented my solution at http://blog.jmoz.co.uk/symfony2-fosuserbundle-role-entities



来源:https://stackoverflow.com/questions/8388080/symfony2-fosuserbundle-role-entities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!