我必须在不同的环境中将参数绑定为不同的值,并且遇到了问题。
我正在尝试这个:
# config/services.yaml
services:
_defaults:
bind:
$param: 'param for PROD'
# config/services_dev.yaml
services:
_defaults:
bind:
$param: 'param for DEV'
# src/Controller/SomeController.php
class MyController extends AbstractController
{
public function example($param)
{
echo $param;
}
}
Run Code Online (Sandbox Code Playgroud)
但它迫使我在services.yaml和services_dev.yaml文件中定义所有服务,否则它不起作用。
我希望为任何环境共享一个services.yaml,并且仅覆盖自定义服务/绑定等,而不是有两个相同的文件,其中列出了用于更改一个绑定值的所有服务。
真正的问题是我必须创建两个具有相同接口的http客户端(真实的和虚拟的),在生产中加载真实的客户端,在开发中加载虚拟的,Symfony 4-s自动装配允许我将接口注入控制器中并选择在绑定中使用哪个客户端:
# config/services.yaml
services:
_defaults:
bind:
'ClientInterface': '@real_client'
# More services here...
# config/services_dev.yaml
services:
_defaults:
bind:
'ClientInterface': '@dummy_client'
# Here I don't want to have another copy of the services,
# but it does not work …Run Code Online (Sandbox Code Playgroud)