我正在尝试创建custom user provider。
我将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
。
我该怎么办?
答案 0 :(得分:2)
服务定义很棘手
myvendor.user_provider:
class: MyVendor\UserBundle\Service\Security\UserProvider
factory_service: doctrine.odm.mongodb
factory_method: getRepository
arguments: [ 'MyVendorUserBundle:User\User' ]