FpOpenIdBundle实现接口错误

时间:2016-01-10 22:33:01

标签: php mongodb symfony

我正在使用FpOpenIdBundle进行身份验证,但我收到此错误

  

捕获致命错误:参数1传递给Fp \ OpenIdBundle \ Model \ UserIdentity :: setUser()必须实现接口Symfony \ Component \ Security \ Core \ User \ UserInterface,Doctrine \ ODM \ MongoDB \ DocumentRepository实例给出,调用在第64行的C:\ xampp \ htdocs \ project \ src \ AppBundle \ Security \ User \ OpenIdUserManager.php中定义

我遵循了文档(https://github.com/formapro/FpOpenIdBundle/blob/master/Resources/doc/configure_user_manager.md

我已成为经理

namespace AppBundle\Security\User;

use AppBundle\Document\User;
use AppBundle\Document\OpenIdIdentity;
use Doctrine\ODM\MongoDB\DocumentManager;
use Fp\OpenIdBundle\Model\UserManager;
use Fp\OpenIdBundle\Model\IdentityManagerInterface;

class OpenIdUserManager extends UserManager
{
   /**
   * @var DocumentManager
   */
   private $documentManager;

    /**
    * OpenIdUserManager constructor.
    *
    * @param IdentityManagerInterface $identityManager
    * @param DocumentManager $documentManager
    */
    public function __construct(IdentityManagerInterface $identityManager, DocumentManager $documentManager)
    {
        parent::__construct($identityManager);

        $this->documentManager = $documentManager;
    }

    /**
     * @param string $identity
     * @param array $attributes
     *
     * @return \Doctrine\ODM\MongoDB\DocumentRepository
     */
     public function createUserFromIdentity($identity, array $attributes = array())
    {

        $user = $this->documentManager->getRepository('AppBundle:User');

        $openIdIdentity = new OpenIdIdentity();
        $openIdIdentity->setIdentity($identity);
        $openIdIdentity->setAttributes($attributes);
        $openIdIdentity->setUser($user);

        $this->documentManager->persist($openIdIdentity);
        $this->documentManager->flush();

        return $user;

    }
}

由于此行

而返回错误
$openIdIdentity->setUser($user);

我使用此经理作为此项服务

services:
fp_openid.manager:
    class: AppBundle\Security\User\OpenIdUserManager
    arguments: [ '@fp_openid.identity_manager', '@doctrine.odm.mongodb.document_manager' ]

我的security.yml打电话给谁。

security:
    firewalls:
       main:
           fp_openid:
               create_user_if_not_exists: true
               provider: openid_user_manager
    providers:
        openid_user_manager:
            id: fp_openid.manager
        main:
            entity:
                { class: AppBundle:User, property: personaName }

我终于根据他们的说法制作了一份MongoDB文件

namespace AppBundle\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Symfony\Component\Security\Core\User\UserInterface;

use Fp\OpenIdBundle\Document\UserIdentity as BaseUserIdentity;

/**
 * @MongoDB\Document(collection="openid_identities")
 */
class OpenIdIdentity extends BaseUserIdentity
{
    /**
     * @MongoDB\Id(strategy="auto")
     */
    protected $id;

    /**
     * {@inheritdoc}
     * @MongoDB\String
     */
     protected $identity;

    /**
     * {@inheritdoc}
     * @MongoDB\Hash
     */
     protected $attributes;

    /**
     * @var UserInterface
     *
     * @MongoDB\ReferenceOne(targetDocument="AppBundle\Document\User", simple=true)
     */
     protected $user;

    public function __construct()
    {
        parent::__construct();
    }
}

除了这个问题,Everythings工作得很好,我不明白为什么这不起作用,而我做同样的文件说。我必须实现UserInterface而不是DocumentRepository的实例,但他们使用他们的用户文档。

是否有人已使用此捆绑包并遇到此问题?

感谢您的帮助

1 个答案:

答案 0 :(得分:2)

请在文档中再次仔细阅读文档:

$user = $this->entityManager->getRepository('AcmeDemoBundle:User')->findOneBy(array(
    'email' => $attributes['contact/email']
));