Search code examples
phpsymfonysymfony-2.7fosoauthserverbundle

FOSOauthServerBundle __constructor error


I've been working a RESTful API for a while now in Symfony 2. Everything seemed to be OK until last night when I created new entity classes. I'm getting an error when trying to request an access token. I get the following error message:

Catchable Fatal Error: Argument 2 passed to
FOS\OAuthServerBundle\Event\OAuthEvent::__construct() must be an
instance of FOS\OAuthServerBundle\Model\ClientInterface, instance of
TeamGraduate\APIBundle\Entity\Client given, called in /Volumes/SK Repo
1.0/Projects/Stalin Kay/Web Development/htdocs/TeamGraduate/tg-api/vendor/friendsofsymfony/oauth-server-bundle/FOS/OAuthServerBundle/Controller/AuthorizeController.php
on line 57 and defined 500 Internal Server Error -
ContextErrorException

Please help. My s2 project uses the FOSOauthServerBundle as described in the documentation. If I override the constructor in Client it throws a fatal error: cannot call constructor.

Edit:

NB: Just to be clear everything was working fine until I generated new entities based on an updated database. I also did an update of the project's dependencies using composer update.

AccessToken.php

<?php
// src/Acme/DemoBundle/Entity/AccessToken.php

namespace TeamGraduate\APIBundle\Entity;

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

/**
 * @ORM\Entity
 */
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="User")
     */
    protected $user;
}

AuthCode.php

<?php
// src/Acme/DemoBundle/Entity/AuthCode.php

namespace TeamGraduate\APIBundle\Entity;

use FOS\OAuthServerBundle\Entity\AuthCode as BaseAuthCode;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class AuthCode extends BaseAuthCode
{
    /**
     * @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="User")
     */
    protected $user;
}

Client.php

<?php
// src/Acme/DemoBundle/Entity/Client.php

namespace TeamGraduate\APIBundle\Entity;

use FOS\OAuthServerBundle\Entity\Client as BaseClient;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class Client extends BaseClient
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    public function __construct()
    {
        parent::__construct();
    }
}

RefreshToken.php

<?php
// src/Acme/DemoBundle/Entity/RefreshToken.php

namespace TeamGraduate\APIBundle\Entity;

use FOS\OAuthServerBundle\Entity\RefreshToken as BaseRefreshToken;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class RefreshToken extends BaseRefreshToken
{
    /**
     * @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="User")
     */
    protected $user;
}

Solution

  • I believe I have found a solution.

    Using the command below creates an FOS directory is created under src

    php app/console doctrine:mapping:import --force TeamGraduateAPIBundle xml
    

    Solution:

    Delete the directory and all should be OK.