Symfony Config 组件允许创建和加载配置。例如,它允许使用 yml 进行配置。
但是,在 Symfony 框架中配置使用具有特殊语法的参数 - %parameter.key%
我查看了 Symfony YamlFileLoader,但它只加载 yaml 文件的内容并处理诸如 imports
之类的部分。 , parameters
和services
。唯一的目标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/