参见英文答案 >
Symfony2 Use PHP Class Constant in YAML Config?6个
使用配置文件定义服务时,如何将PHP常量(本例中为CURLAUTH_DIGEST)作为构造函数参数传递?
使用配置文件定义服务时,如何将PHP常量(本例中为CURLAUTH_DIGEST)作为构造函数参数传递?
我现在无法测试它,但我认为:
services:
my_service:
class: "%my_service.class%"
arguments: [CURLAUTH_DIGEST]
因为CURLAUTH_DIGEST被转换为字符串而无法工作.
这是一种方法
>在配置中添加一行以包含.PHP配置
应用程序/配置/ config.yml
imports:
- { resource: constants.PHP }
>创建一个新文件constants.PHP
应用程序/配置/ constants.PHP
<?PHP
$container->setParameter('curlauth.digest',CURLAUTH_DIGEST);
>您现在可以在服务中访问此常量
@包/资源/配置/ services.yml
services:
my_service:
class: "%my_service.class%"
arguments: [%curlauth.digest%]