Symfony2 - 为FOSOAuthServerBundle使用yml

时间:2014-04-22 09:11:54

标签: php symfony fosoauthserverbundle

我正在尝试使用symfony2中的FOSOAuthServer包创建一个Web服务。

我正在使用yml配置;所以我像这样为AcccessToken创建实体:

YML:

My\ApiBundle\Entity\AccessToken:
    type:  entity
    table: access_token
    id:
        id:
            type: integer
            generator:
                strategy: AUTO

    manyToOne:
        client:
            targetEntity: Client
            inversedBy: access_tokens
            joinColumn:
                name: client_id
                referencedColumnName: id
                nullable: false

        user:
            targetEntity: User
            inversedBy: access_tokens
            joinColumn:
                name: user_id
                referencedColumnName: id

实体:

<?php

namespace My\ApiBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use FOS\OAuthServerBundle\Entity\AccessToken as BaseAccessToken;

/**
 * AccessToken
 */
class AccessToken extends BaseAccessToken
{
    /**
     * @var integer
     */
    protected $id;


    /**
     * @var \My\ApiBundle\Entity\Client
     */
    protected $client;


    /**
     * @var \My\ApiBundle\Entity\User
     */
    protected $user;



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

    /**
     * Set client
     *
     * @param \My\ApiBundle\Entity\Client $client
     * @return AccessToken
     */
    public function setClient(\My\ApiBundle\Entity\Client $client)
    {
        $this->client = $client;

        return $this;
    }

    /**
     * Get client
     *
     * @return \My\ApiBundle\Entity\Client 
     */
    public function getClient()
    {
        return $this->client;
    }

    /**
     * Set user
     *
     * @param \My\ApiBundle\Entity\User $user
     * @return AccessToken
     */
    public function setUser(\My\ApiBundle\Entity\User $user = null)
    {
        $this->user = $user;

        return $this;
    }

    /**
     * Get user
     *
     * @return \My\ApiBundle\Entity\User 
     */
    public function getUser()
    {
        return $this->user;
    }
}

现在当我再次运行generate entities命令时,它会抛出此错误。

  

致命错误:声明My \ ApiBundle \ Entity \ AccessToken :: setUser()   必须兼容   FOS \ OAuthServerBundle \型号\ TokenInterface :: SETUSER(Symfony的\分量\安全\核心\用户\的UserInterface   $ user)in   D:\ xampp \ htdocs \ oauth \ src \ My \ ApiBundle \ Entity \ AccessToken.php在线   12

我做错了什么?我正在关注here的文档。

1 个答案:

答案 0 :(得分:2)

您不能破坏setUser方法定义(在接口中定义)。它必须与TokenInterface中的完全相同。

变化:

public function setUser(\My\ApiBundle\Entity\User $user = null)

要:

public function setUser(\Symfony\Component\Security\Core\User\UserInterface $user = null)