0

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

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

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;
    }
}

现在,当我再次运行生成实体命令时,它会引发此错误。

致命错误:My\ApiBundle\Entity\AccessToken::setUser() 的声明必须与 D:\ 中的 FOS\OAuthServerBundle\Model\TokenInterface::setUser(Symfony\Component\Security\Core\User\UserInterface $user) 兼容xampp\htdocs\oauth\src\My\ApiBundle\Entity\AccessToken.php 在第 12 行

我究竟做错了什么?我正在关注这里的文档。

4

1 回答 1

2

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

改变:

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

至:

public function setUser(\Symfony\Component\Security\Core\User\UserInterface $user = null)
于 2014-04-22T09:25:31.990 回答