Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
来自控制器的Symfony set services.yml参数_Symfony - Fatal编程技术网

来自控制器的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');
这只是一个答案。任何更好的解决方案都可能存在