Symfony DI 调用静态方法

Mic*_*ski 2 dependency-injection symfony

我使用这个库https://github.com/smsapi/smsapi-php-client从网站发送短信。但是当我尝试处理服务中的基类时遇到了问题。所以我的问题是有没有办法用参数调用静态方法?我尝试通过工厂来做到这一点,但这对我不起作用。这是我的代码:

smsapi.client:
   class: SMSApi\Client
   factory: ['SMSApi\Client', createFromToken]
   properties:
       attributes: '%smsapi_token%'
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误:

Warning: Missing argument 1 for SMSApi\Client::createFromToken(), called in ../cache/dev/appDevDebugProjectContainer.php on line 5073 and defined
Run Code Online (Sandbox Code Playgroud)

Mat*_*teo 5

如文档中所述:将参数传递给工厂方法

您可以使用arguments服务容器内的选项。

例如:

smsapi.client:
   class: SMSApi\Client
   factory: ['SMSApi\Client', createFromToken]
   arguments:
       attributes: '%smsapi_token%'
Run Code Online (Sandbox Code Playgroud)

希望这有帮助

PS:请分享您正在使用的库的存储库或源代码的主要部分,以便处理这种情况。