[英]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. 我已经在Symfony 2中使用RESTful API已有一段时间了,直到昨晚创建新的实体类时,一切似乎都还可以。 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. 我的s2项目使用FOSOauthServerBundle,如文档中所述。 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. 我还使用composer update对项目的依赖项进行了更新。
AccessToken.php 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 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 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 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;
}
I believe I have found a solution. 我相信我已经找到了解决方案。
Using the command below creates an FOS directory is created under src 使用下面的命令在src下创建一个FOS目录
php app/console doctrine:mapping:import --force TeamGraduateAPIBundle xml
Solution: 解:
Delete the directory and all should be OK. 删除目录,一切都应该没问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.