vansanblch vansanblch - 7 months ago 34
YAML Question

How does a Symfony pass parameters into a yaml config?

A Symfony Config component allows to create and load a configuration. For instance, it allows to use a yml for config.

However, in a Symfony framework configuration uses parameters with a special syntax -

%parameter.key%


I've looked at Symfony YamlFileLoader but it only load a content of a yaml-file and handle such sections as
imports
,
parameters
and
services
. The only goal of the
parameters
is to be stored in a container parameter bag.

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

Moreover. I've tried to load a config:

application:
aBooleanKey: "true"


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

Answer Source

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

This Parameters are part of the Dependency Injection component, not the Config.

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

Not quite. Special compiler pass resolves the placeholders. It works at the optimization step of the container compilation and inject actual values, so that placeholders can be used in the service definitions and in the semantic configuration files.

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

I guess that caused by 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);

...

So, in your example true is quoted and treated as string.