从定制服务类中,可以通过将服务ParameterBagInterface注入服务类的构造函数中来轻松获得在services.yaml文件中定义的参数,如下所示:
#from the services.yaml
...
services:
...
App\Utils\myCustomService:
arguments:
$faa: 'some value'
...
//from my custom service Class
...
public function __construct(ParameterBagInterface $faa){
dump($faa); //print 'some value';
}
但是由于某种原因,我想在服务的构造函数中使用“正常”参数,如下所示:
//from my custom service Class
...
public function __construct($aNormalParameter){
// do some stuff with $aNormalParameter
// but I also want to work with the $faa value located in the services.yaml file, how can I do that ?
}
//from a custom Controller
...
public function home(){
$myCustomService = new App\Utils\myCustomService("blabla");
}
所以我的问题是,如何在不将ParameterBagInterface服务注入构造函数的情况下访问在services.yaml文件中定义的参数?
谢谢:)