2015-11-06 85 views
2

我已經在Symfony 2中使用了一段時間的RESTful API。在創建新的實體類之前,一切似乎一直持續到昨天晚上。嘗試請求訪問令牌時出現錯誤。我收到以下錯誤信息:FOSOauthServerBundle __constructor錯誤

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 

請幫忙。我的s2項目使用文檔中描述的FOSOauthServerBundle。如果我重寫Client中的構造函數,它會引發一個致命錯誤:無法調用構造函數。

編輯:

NB:只要是明確的一切工作正常,直到我生成基於​​數據庫更新資料的新實體。我還使用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; 
} 
+0

你的'Client'實體是否實現'ClientInterface'?你可以發佈它嗎? – chapay

+0

@chapay,我沒有實現ClientInterface。我使用[link](https://github.com/FriendsOfSymfony/FOSOAuthServerBundle/blob/master/Resources/doc/index.md) –

+0

擴展FOS \ OAuthServerBundle \ Model \ Client not Entity \ Client – Udan

回答

0

我相信我已經找到了解決辦法。

使用下面的命令創建一個FOS目錄下創建的src

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

解決方案:

刪除目錄,都應該確定。

相關問題