doufan3958 2015-11-06 15:18
浏览 30
已采纳

FOSOauthServerBundle __constructor错误

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;
}
  • 写回答

1条回答 默认 最新

  • dtstnjl898781429 2015-11-09 08:53
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器