use*_*963 3 doctrine symfony doctrine-orm
我创建了一个包来管理用户组权限.我希望它通过将项目移动到供应商目录来使项目独立.
为了使这个包不可变,我将用户数据移动到usermeta包中.
主捆绑包含有关用户的用户名和电子邮件,而usermeta包含其他所有内容(名称,生日等,无论项目需要什么).
问题是主要用户捆绑包意图属于核心捆绑组,每个项目使用相同的捆绑组.
user-usermeta关系现在创建了一个依赖项.所以每个项目都需要它.
我的问题是
- 我如何标准化其格式,在每个项目中强制执行它.
- 如何使此依赖项可选(首选)
我建议您只处理UserInterface而不是捆绑中的User实体.
如果Symfony UserInterface没有实现您需要的所有内容(用户名但没有电子邮件),请在您的包中创建您自己的UserInterface:
namespace YourDomain\YourBundle\Interface;
use Symfony\Component\Security\Core\User\UserInterface as BaseInterface;
/**
* UserInterface is the interface that user classes must implement.
*/
interface UserInterface extends BaseInterface
{
/**
* Returns the email address of the user.
*
* @return string The user email address
*/
function getEmail();
}
Run Code Online (Sandbox Code Playgroud)
然后,在使用您的bundle的项目中,您的User实体必须实现您的特定接口而不是Symfony UserInterface.