来自控制器的Symfony set services.yml参数
有没有一种方法可以从控制器设置令牌参数来自控制器的Symfony set services.yml参数,symfony,Symfony,有没有一种方法可以从控制器设置令牌参数 app.oauth_subscriber: class: GuzzleHttp\Subscriber\Oauth\Oauth1 arguments: - consumer_key: 'test' private_key_file: '../app/config/test.pem' private_key_passphrase: null signature_meth
app.oauth_subscriber:
class: GuzzleHttp\Subscriber\Oauth\Oauth1
arguments:
- consumer_key: 'test'
private_key_file: '../app/config/test.pem'
private_key_passphrase: null
signature_method: !php/const:GuzzleHttp\Subscriber\Oauth\Oauth1::SIGNATURE_METHOD_RSA
token: "@=service('security.token_storage').getToken().getUser().getToken().getAccessToken()"
我可以得到这样的服务:
$this->container->get('app.oauth_subscriber');
我不确定您是否可以使用服务工厂来完成这项工作,但如果您不需要令牌作为构造,您可以将其从服务参数中删除,并在服务中声明新方法,如
setToken()
,并在控制器中将其用于设置令牌
// Service
private $token;
public function setToken($token){
$this->token = $token;
}
并在您的服务中使用$this->token
// Controller
$myService = $this->container->get('app.oauth_subscriber');
$myService->setToken('token');
这只是一个答案。任何更好的解决方案都可能存在