我正在尝试使用symfony2中的FOSOAuthServer捆绑包创建一个web服务。
我使用yml配置;所以我为AccessToken创建了这样的实体:
yml:
MyApiBundleEntityAccessToken:
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 MyApiBundleEntity;
use DoctrineORMMapping as ORM;
use FOSOAuthServerBundleEntityAccessToken as BaseAccessToken;
/**
* AccessToken
*/
class AccessToken extends BaseAccessToken
{
/**
* @var integer
*/
protected $id;
/**
* @var MyApiBundleEntityClient
*/
protected $client;
/**
* @var MyApiBundleEntityUser
*/
protected $user;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set client
*
* @param MyApiBundleEntityClient $client
* @return AccessToken
*/
public function setClient(MyApiBundleEntityClient $client)
{
$this->client = $client;
return $this;
}
/**
* Get client
*
* @return MyApiBundleEntityClient
*/
public function getClient()
{
return $this->client;
}
/**
* Set user
*
* @param MyApiBundleEntityUser $user
* @return AccessToken
*/
public function setUser(MyApiBundleEntityUser $user = null)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* @return MyApiBundleEntityUser
*/
public function getUser()
{
return $this->user;
}
}
现在,当我再次运行generateentities命令时,它会抛出这个错误。
致命错误:声明My\ApiBundle\Entity\AccessToken::setUser()必须与兼容FOS\OAuthServerBundle\Model\TokenInterface::setUser(Symfony\Component\Security\Core\User\UserInterface$user)D: \examplep\htdocs\oauth\src\My\ApiBundle\Entity\AccessToken.php在线12
我做错了什么?我在这里关注文档。
您不能破坏setUser方法定义(在接口中定义)。它必须与TokenInterface中的完全相同。
更改:
public function setUser(MyApiBundleEntityUser $user = null)
收件人:
public function setUser(SymfonyComponentSecurityCoreUserUserInterface $user = null)