Symfony OAuth api FOSOAuthServerBundle: crash

Pro*_*mer 3 php oauth symfony oauth-2.0 fosuserbundle

Am trying to use the FOSOAuthServerBundle but am having a crash problem, the crash message is :

PHP Fatal error:  Declaration of MP\OAuthBundle\Entity\AccessToken::setUser() must be compatible with that of FOS\OAuthServerBundle\Model\TokenInterface::setUser() in /home/bitnami..../OAuthBundle/Entity/AccessToken.php on line 13
Run Code Online (Sandbox Code Playgroud)

AccessToken.class:

<?php

namespace MP\OAuthBundle\Entity;

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

/**
 * @ORM\Entity
 * @ORM\Table(name="oauth_access_tokens")
 */
class AccessToken extends BaseAccessToken
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\ManyToOne(targetEntity="Client")
     * @ORM\JoinColumn(nullable=false)
     */
    protected $client;

    /**
     * @ORM\ManyToOne(targetEntity="\MP\UserBundle\Entity\User")
     */
    protected $user;
}
Run Code Online (Sandbox Code Playgroud)

TokenInterface::setUser:

 /**
     * @param UserInterface $user
     */
    function setUser(UserInterface $user);
Run Code Online (Sandbox Code Playgroud)

User.class

namespace MP\UserBundle\Entity;

use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;


/**
 * User
 */
class User extends BaseUser
{
    const ROLE_ADMIN = 'ROLE_ADMIN';

    /**
     * @var integer
...
Run Code Online (Sandbox Code Playgroud)

I still do not see where the problem can be ! My user is implementing the UserInterface at the end!

Any idea?

Nic*_*ich 5

请确保您有以下两个使用语句MP\OAuthBundle\Entity\AccessToken

use Symfony\Component\Security\Core\User\UserInterface;
use FOS\OAuthServerBundle\Model\ClientUserInterface;
Run Code Online (Sandbox Code Playgroud)

你必须确保AccessToken机具FOS\OAuthServerBundle\Model\TokenInterface,其中包括函数声明具有相同的接口.

现在,如果你有......

function setUser(UserInterface $user)
Run Code Online (Sandbox Code Playgroud)

...内部AccessToken尝试实现TokenInterface但没有使用声明......

...... UserInterface会翻译成MP\OAuthBundle\Entity\UserInterface

......但它需要Symfony\Component\Security\Core\User\UserInterface.


结论

参数类型之间的不匹配是PHP抱怨这里两个函数声明之间不匹配的原因.