我已经在Symfony 2中使用RESTful API了一段时间。直到昨晚我创建新的实体类时,一切似乎都没问题。我在尝试请求访问令牌时遇到错误。我收到以下错误消息:
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。如果我覆盖客户端中的构造函数,则会抛出致命错误:无法调用构造函数。
修改
注意:要明确一切正常,直到我根据更新的数据库生成新实体。我还使用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 :(得分:0)
我相信我找到了解决方案。
使用以下命令创建在src
下创建的FOS目录php app/console doctrine:mapping:import --force TeamGraduateAPIBundle xml
<强>解决方案:强>
删除目录,一切都没问题。