2012-09-30 28 views
1

我正在嘗試創建custom user provider不能使用Doctrine知識庫作爲用戶提供者

我定義我的UserProvider作爲一項服務:

myvendor.user_provider: 
    class: MyVendor\UserBundle\Service\Security\UserProvider 

這個類是一個DocumentRepository

namespace MyVendor\UserBundle\Service\Security; 

use Symfony\Component\Security\Core\User\UserInterface; 
use Symfony\Component\Security\Core\User\UserProviderInterface; 
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; 
use Symfony\Component\Security\Core\Exception\UnsupportedUserException; 
use Doctrine\ODM\MongoDB\DocumentRepository; 
use Doctrine\ODM\MongoDB\DocumentNotFoundException; 

class UserProvider extends DocumentRepository implements UserProviderInterface { 
    //public function loadUserBy... 
} 

但我得到這個錯誤:

Catchable Fatal Error: Argument 1 passed to Doctrine\ODM\MongoDB\DocumentRepository::__construct() must be an instance of Doctrine\ODM\MongoDB\DocumentManager, none given, called in /home/www/dev/public/myapp/app/cache/dev/appDevDebugProjectContainer.php on line 258 and defined in /home/www/dev/public/myapp/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/DocumentRepository.php line 68 

似乎是文檔管理器目前尚未創建,因爲我也嘗試注入它,但它抱怨自己的依賴,如UnitOfWork

我該怎麼辦?

回答

2

服務定義是棘手

myvendor.user_provider: 
    class: MyVendor\UserBundle\Service\Security\UserProvider 
    factory_service: doctrine.odm.mongodb 
    factory_method: getRepository 
    arguments: [ 'MyVendorUserBundle:User\User' ] 
+0

非常感謝你非常喜歡。 – mojotaker

相關問題