如何在Symfony 2中将PHP常量作为服务参数传递?
使用配置文件定义服务时,如何将PHP常量(如何在Symfony 2中将PHP常量作为服务参数传递?,symfony,constants,yaml,Symfony,Constants,Yaml,使用配置文件定义服务时,如何将PHP常量(CURLAUTH_DIGEST)作为构造函数参数传递 我现在无法测试它,但我假设: 服务: 我的服务: 类别:“%my_服务。类别%” 参数:[CURLAUTH_摘要] 因为CURLAUTH\u DIGEST被转换为字符串以下是一种方法 在配置中添加一行以包含.php配置 app/config/config.yml 创建一个新文件constants.php app/config/constants.php 谢谢,这向我们展示了如何在YAML中实现这
CURLAUTH_DIGEST
)作为构造函数参数传递
我现在无法测试它,但我假设:
服务:
我的服务:
类别:“%my_服务。类别%”
参数:[CURLAUTH_摘要]
因为
CURLAUTH\u DIGEST
被转换为字符串
以下是一种方法
.php
配置
app/config/config.yml
constants.php
app/config/constants.php
谢谢,这向我们展示了如何在YAML中实现这一点。重复的答案(我读得不太好)表明这是不可能的(仅在XML中)。我投票决定关闭,现在我决定重新开放。
imports:
- { resource: constants.php }
<?php
$container->setParameter('curlauth.digest', CURLAUTH_DIGEST);
services:
my_service:
class: "%my_service.class%"
arguments: [%curlauth.digest%]