php - Symfony 如何将参数传递到 yaml 配置中?

标签 php symfony yaml

Symfony Config 组件允许创建和加载配置。例如,它允许使用 yml 进行配置。

但是,在 Symfony 框架中配置使用具有特殊语法的参数 - %parameter.key%

我查看了 Symfony YamlFileLoader,但它只加载 yaml 文件的内容并处理诸如 imports 之类的部分。 , parametersservices 。唯一的目标parameters是存储在容器参数包中。

所以我想知道用什么魔法来替换 yaml 配置文件中的占位符?

此外。我尝试加载配置:

application:
    aBooleanKey: "true"

aBooleanKey 以来我遇到了一个错误需要一个 bool 值,但得到一个字符串。

最佳答案

So I'm wondering what's magic used to replace placeholders in a yaml config file?

此参数是 Dependency Injection 的一部分组件,而不是 Config

The only goal of the parameters is to be stored in a container parameter bag.

不完全是。 Special compiler pass解析占位符。它在 container compilation 的优化步骤中起作用。并注入(inject)实际值,以便可以在服务定义和语义配置文件中使用占位符。

... and I've got an error since aBooleanKey requires a boolean value but got a string.

我猜这是由 YAML Component 引起的:

Finally, there are other cases when the strings must be quoted, no matter if you're using single or double quotes:

  • When the string is true or false (otherwise, it would be treated as a boolean value);

...

因此,在您的示例中 true 被引用并被视为字符串。

关于php - Symfony 如何将参数传递到 yaml 配置中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43095127/

相关文章:

php - 输出缓冲 ob_get_clean 不工作

Symfony 应用程序无法获得 Traefik 和 Nginx 代理背后的 HTTPS 流量

php - 从使用ajax获取的json创建html

php - 从 Zend Framework 2 在 mysql 中插入 BIT 列

javascript - jQuery 验证器插件 - 检查 mysql 数据库中的现有用户名/电子邮件

php - 存储餐厅签到计数等数据的最佳方式?

symfony - 在功能测试中使用全局变量(使用 Symfony 和 Codeception)

symfony - 如何在parameters.yml symfony2中转义 "%"

java - 无法连接到数据库

yaml - Jekyll/Liquid - 如何将大块文本添加到 YAML 前面的内容?