【问题标题】:Can't use a Doctrine repository as user provider不能使用 Doctrine 存储库作为用户提供者
【发布时间】:2012-09-21 21:09:58
【问题描述】:

我正在尝试创建一个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

我能做什么?

【问题讨论】:

    标签: security mongodb symfony doctrine-orm symfony-2.1


    【解决方案1】:

    服务定义很棘手

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-31
      • 2019-10-19
      • 1970-01-01
      • 2011-03-14
      • 1970-01-01
      • 2015-04-28
      • 2016-12-30
      • 1970-01-01
      相关资源
      最近更新 更多