【发布时间】:2019-05-15 03:57:19
【问题描述】:
我正在使用以下软件包:
"friendsofsymfony/oauth-server-bundle": "^1.6",
"friendsofsymfony/rest-bundle": "^2.5",
"friendsofsymfony/user-bundle": "^2.1",
"symfony/framework-bundle": "4.2.*",
"symfony/http-foundation": "4.2.*",
"symfony/http-kernel": "4.2.*"
我正在尝试覆盖 FOSOAuthServerBundle 包的 tokenAction 方法,但我遇到了错误:
"Cannot autowire service App\Controller\TokenController argument $server of method FOS\OAuthServerBundle\Controller\TokenController::__construct() references class OAuth2\OAuth2; but no such service exists. You should maybe alias this class to the existing fos_oauth_server.server service"
我尝试了几种不同的方法(自动装配、自动注入),但我不断回到上面描述的错误。似乎“使用 OAuth2\OAuth2;”引用在包的 TokenController 中正确命名,但是当我尝试覆盖它时无法正确解析 OAuth2 类位置,我不确定在类或 services.yaml 中使用什么模式将其指向正确的位置.
这是我的 services.yaml
services:
...
App\Controller\TokenController\:
resource: '../src/Controller/TokenController.php'
arguments: ['@fos_oauth_server.server']
还有我的自定义 TokenController 类
?php
namespace App\Controller;
use FOS\OAuthServerBundle\Controller\TokenController as BaseController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class TokenController extends BaseController
{
/**
* @param Request $request
*
* @return Response
*/
public function tokenAction(Request $request)
{
$token = parent::tokenAction($request);
// my custom code here
return $token;
}
}
如果我尝试做显而易见的事情并添加一行
use OAuth2\OAuth2;
到我的自定义 TokenController 我得到了同样的错误。
【问题讨论】:
标签: php symfony oauth-2.0 fosoauthserverbundle