2012-02-24 119 views
3

我創建了一個包來管理用戶組權限。我希望它通過將它移動到供應商目錄來使項目獨立。
爲了使這個包不可變,我將用戶數據移到了一個usermeta包中。
主要包僅包含關於用戶的用戶名和電子郵件,並且usermeta包含所有其他內容(名稱,生日等,無論項目需要)。Symfony 2軟件包依賴項問題

問題是打算屬於核心捆綁包組的主用戶捆綁包,每個項目使用相同的捆綁組。
用戶 - 用戶元關係現在創建了一個依賴關係。所以每個項目都需要它。

我的問題是
- 如何規範它的格式,在每一個項目執行正確地創建它。
- 我怎樣才能使這種依賴性可選(首選)

回答

5

我建議你只處理一個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(); 
} 

,然後在項目中,您的用戶:

在Symfony的的UserInterface的情況下沒有實現你所需要的一切信息(用戶名,但沒有電子郵件),在你的包創建自己的UserInterface實體必須實現您的特定接口而不是Symfony UserInterface。

+0

爲了完整起見,您可以參考官方文檔:http://symfony.com/doc/master/cookbook/doctrine/resolve_target_entity.html – 2012-07-23 10:48:47