Symfony2 FOSUserBundle 角色实体 [英] Symfony2 FOSUserBundle Role entities

查看:21
本文介绍了Symfony2 FOSUserBundle 角色实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试找出将原则持久化角色实体实现为与 FOSUserBundle 兼容的 M2M 关系的最佳方法.以前,我只使用带有默认实现的字符串,并通过一个学说数组映射来持久化它.

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.

基本上,这是一种痛苦.FOS 接口是为字符串表示而构建的,而不是为角色实体构建的.改变实现,你打破了很多东西,即促进用户的 FOS 命令.并且很难确定到底需要哪些接口才能让 symfony2 安全系统继续正常工作.

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?

或继续使用:

$user->addRole('ROLE_FOO');

addRole() 中耦合角色/实体管理器代码(糟糕的设计).

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

我注意到这是一个灰色区域(具有 FOS 的角色实体)并且在 symfony2 董事会和此处都提到过,但没有合适的解决方案.

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?

推荐答案

我决定混合使用数组/ArrayCollection 实现.我尽量遵循现有的接口,以免破坏安全系统.我在 http://blog.jmoz.co.uk/symfony2-fosuserbundle-role-记录了我的解决方案实体

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

这篇关于Symfony2 FOSUserBundle 角色实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆