我正在尝试将自定义UserProvider与FOS用户捆绑包和FOS Oauth包一起使用。我一直在学习本教程http://blog.tankist.de/blog/2013/07/17/oauth2-explained-part-2-setting-up-oauth2-with-symfony2-using-fosoauthserverbundle/.
当我尝试注册我的新用户服务时,我得到了以下错误
UserProvider::__construct() must implement interface DoctrineCommonPersistenceObjectRepository, array given
用户提供商:
UserProvider implements UserProviderInterface
{
/**
* @var ObjectRepository
*/
protected $userRepository;
/**
* @param ObjectRepository $userRepository
*/
public function __construct(ObjectRepository $userRepository)
{
$this->userRepository = $userRepository;
}
/**
* @param string $username
* @return mixed
*/
public function loadUserByUsername($username)
{ ... }
用户存储库
class UserRepository extends EntityRepository implements ObjectRepository
services.yml
parameters:
entity_name: HornbyUserBundleEntityUserRepository
services:
user_provider_me:
class: HornbyUserBundleProviderUserProvider
arguments:
name: [%entity_name%]
services.yml文件错误。我真的不确定你想要实现什么,但你通过了阵列
arguments:
name: [%entity_name%] #entity_name is just a string
作为CCD_ 3类的参数。此类的构造函数需要ObjectRepository
,这就是您的问题所在。
您提供的链接对services.xml的翻译应该是这样的:
parameters:
platform.entity.user.class: AcmeDemoBundleEntityUser
platform.user.provider.class: AcmeDemoBundleProviderUserProvider
services:
platform.user.manager:
class: DoctrineORMEntityManager
factory: ["@doctrine", getManagerForClass]
arguments: [%platform.entity.user.class%]
platform.user.repository:
class: AcmeDemoBundleRepositoryUserRepository
factory: ["@platform.user.manager", getRepository]
arguments: [%platform.entity.user.class%]
platform.user.provider:
class: %platform.user.provider.class%
arguments: [@platform.user.repository]