Symfony2 FOSUserBundle Role Objects

I am currently trying to find the best way to implement the doctrinal objects associated with a role, like M2M relationships compatible with FOSUserBundle. Previously, I used only strings with a default implementation and saved it by matching an array of doctrines.

Now I need to have the roles as separate, since we want to create an admin backend where others can provide roles to users.

Basically, this is a pain in the ass. FOS interfaces are built to represent strings, not Role objects. Change the implementation, you will break a lot of things, that is, FOS-commands for promoting users. And it's hard to determine which parts of the interfaces are necessary for the symfony2 security system to continue to work correctly.

I could rewrite the role management code and use Role roles as much as possible, for example:

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

But does this violate commands and possibly existing code?

Or keep using:

 $user->addRole('ROLE_FOO'); 

And add the role / entity manager code to addRole() (bad design).

I noticed that this is a gray area (role objects with FOS) and is mentioned on symfony2 boards here, but there are no decent solutions.

Has anyone had any experience or can come up with a decent solution?

+8
symfony doctrine2 user-roles
source share
1 answer

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

+11
source share

All Articles