3

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

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

TokenInterface::setUser:

 /**
     * @param UserInterface $user
     */
    function setUser(UserInterface $user);

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
...

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

Any idea?

2 Answers 2

5

Make sure you have the following two use-statements in MP\OAuthBundle\Entity\AccessToken

use Symfony\Component\Security\Core\User\UserInterface;
use FOS\OAuthServerBundle\Model\ClientUserInterface;

You have to make sure AccessToken implements FOS\OAuthServerBundle\Model\TokenInterface which includes function declaration with the same interfaces.

now if you have ...

function setUser(UserInterface $user)

... inside AccessToken trying to implement TokenInterface but without the use statement ...

... UserInterface would translate to MP\OAuthBundle\Entity\UserInterface

... but it needs to be Symfony\Component\Security\Core\User\UserInterface.


conclusion

Mismatch between argument types is why PHP complains about the mismatch between the two function declarations here.

Sign up to request clarification or add additional context in comments.

Comments

2

The problem is within your Access token class. You probably override setUser() method (without pasting it here), and not adding Symfony\Component\Security\Core\User\UserInterface to use statements. There is no other way since you class is first and last overriding FOS FOS\OAuthServerBundle\Model\AccessToken.

Delete this function definition from you class or fix use statements

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.