2012-04-11 19 views
0

私はFOSUserBundleをFpOpenIDBundleと統合しようとしましたが、authが処理されるときに問題が発生しました。 エラーが発生するSymfony 2.0 FOSUserBundle with OpenID

"Alef \ UserBundle \ Entity \ User"のインスタンスはサポートされていません。

私のクラスには、私はFpOpenIdは、元のsymfonyのセキュリティ・ユーザー・クラスを継承していますが、FOSUSerはそれから継承していないので、それは継承の問題を知っているこの

<?php 

namespace Alef\UserBundle\Entity; 

use Doctrine\Common\Collections\ArrayCollection; 
use Doctrine\Common\Collections\Collection; 
use FOS\UserBundle\Entity\User as BaseUser; 
use FOS\UserBundle\Model\GroupInterface; 
use Doctrine\ORM\Mapping as ORM; 


/** 
* User Entity 
* 
* @ORM\Entity 
* @ORM\Table(name="alef_users") 
* 
* @author James Morris <[email protected]> 
* @package SecurityBundle 
*/ 
class User extends BaseUser implements \FOS\UserBundle\Model\GroupableInterface 
{ 
    /** 
    * @ORM\Id 
    * @ORM\Column(type="integer") 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $id; 

    /** 
    * @ORM\ManyToMany(targetEntity="Alef\UserBundle\Entity\Group") 
    * @ORM\JoinTable(name="alef_user_groups", 
    *  joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}, 
    *  inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")} 
    *) 
    */ 
    protected $groups; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="firstname", type="string", length=255) 
    */ 
    protected $firstname; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="lastname", type="string", length=255) 
    */ 
    protected $lastname; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="facebookId", type="string", length=255) 
    */ 
    protected $facebookId; 

    /** 
    * Get id 
    * 
    * @return integer 
    */ 
    public function getId() 
    { 
     return $this->id; 
    } 

    public function serialize() 
    { 
     return serialize(array($this->facebookId, parent::serialize()));; 
    } 

    public function unserialize($data) 
    { 
     list($this->facebookId, $parentData) = unserialize($data); 
     parent::unserialize($parentData); 
    } 

    /** 
    * @return string 
    */ 
    public function getFirstname() 
    { 
     return $this->firstname; 
    } 

    /** 
    * @param string $firstname 
    */ 
    public function setFirstname($firstname) 
    { 
     $this->firstname = $firstname; 
    } 

    /** 
    * @return string 
    */ 
    public function getLastname() 
    { 
     return $this->lastname; 
    } 

    /** 
    * @param string $lastname 
    */ 
    public function setLastname($lastname) 
    { 
     $this->lastname = $lastname; 
    } 

    /** 
    * Get the full name of the user (first + last name) 
    * @return string 
    */ 
    public function getFullName() 
    { 
     return $this->getFirstName() . ' ' . $this->getLastname(); 
    } 

    /** 
    * @param string $facebookId 
    * @return void 
    */ 
    public function setFacebookId($facebookId) 
    { 
     $this->facebookId = $facebookId; 
     $this->setUsername($facebookId); 
     $this->salt = ''; 
    } 

    /** 
    * @return string 
    */ 
    public function getFacebookId() 
    { 
     return $this->facebookId; 
    } 

    /** 
    * @param Array 
    */ 
    public function setFBData($fbdata) 
    { 
     if (isset($fbdata['id'])) { 
      $this->setFacebookId($fbdata['id']); 
      $this->addRole('ROLE_FACEBOOK'); 
     } 
     if (isset($fbdata['first_name'])) { 
      $this->setFirstname($fbdata['first_name']); 
     } 
     if (isset($fbdata['last_name'])) { 
      $this->setLastname($fbdata['last_name']); 
     } 
     if (isset($fbdata['email'])) { 
      $this->setEmail($fbdata['email']); 
     } 
    } 

    public function __construct() 
    { 
     parent::__construct(); 
     $this->facebookId = 0; 
    } 

} 

のように見えます。実際にFPOpenIDBundleを更新する方法はありますか?

+0

お知らせを追加します。それは1年間更新されておらず、getExtraInformation()のような重要なメソッドは非難されているので、現在のPHP/Symfony2バージョンを打ち破ります。 – Tom

答えて

0

鉱山の設定は次のようになります。

use FOS\UserBundle\Model\User as BaseUser; 
use Symfony\Component\Validator\Constraints as Assert; 
use Symfony\Component\Security\Core\Role\RoleInterface; 
use Symfony\Component\Security\Core\User\UserInterface as SecurityUserInterface; 

class User implements UserInterface, GroupableInterface 
{ 
} 

私が原因ハイパーカスタム機能のクラス全体を上書きしました。あなたの正気を維持したい場合はもうfpOpenIDを使用しないでください:

だけ

class User extends BaseUser implements UserInterface, GroupableInterface 

よろしく、 マックス

+0

何を待ちますか? FoS Userクラス全体を書き直しましたか? – Kaminari

+0

FoS-User-classは特別なものではありません(https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Model/User.php)。 FoSUserBundle-docsで、Userクラスを拡張することができる(ただし_ _含まない) – KingCrunch

+0

ユーザクラスはどれですか?ご覧のとおり、私はUserクラスを拡張していますが、FOS Userクラスは拡張しています。しかしそれだけでは不十分です。 Symfonyユーザクラスである必要があります。 – Kaminari

0
use FOS\UserBundle\Model\GroupableInterface; 
use FOS\UserBundle\Model\GroupInterface; 

class User extends BaseUser 
{ 
    public function addGroup(GroupInterface $group) 
    { 
     parent::addGroup($group); 
    } 
} 
関連する問題