Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Symfony 2中将PHP常量作为服务参数传递?_Symfony_Constants_Yaml - Fatal编程技术网

如何在Symfony 2中将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中实现这

使用配置文件定义服务时,如何将PHP常量(
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%]