In the Configuration of my bundle I have defined the following for example:
$treeBuilder = new TreeBuilder('foo');
$treeBuilder
->getRootNode()
->children()
->arrayNode('foobar')
->scalarPrototype()->end()
->defaultValue([])
->end()
->end()
;
i. e., the bundle expects an array of values in foo.foobar. Now, in the case of my bundle, these values are dependent on the environment the application is run in. Thus it would make sense to provide this configuration value through an environment variable. Since Symfony 3.4 values of environment variables can be processed. So this array could be stored JSON encoded in the environment variable and then be decoded via %env(json:FOO)%. So instead of having to write
foo:
foobar:
- Lorem
- Ipsum
- Dolor
one could instead use
foo:
foobar: '%env(json:FOO)%'
where
FOO=["Lorem","Ipsum","Dolor"]
However, when trying to do that Symfony throws the following exception:
A dynamic value is not compatible with a "Symfony\Component\Config\Definition\PrototypedArrayNode" node type at path "foo.foobar".
What is the correct way of allowing such dynamic values for array nodes? Do I need to implement my own normalization in the configuration tree for example?
%env(string[]:json:FOO)%Invalid "env(string[]:json:FOO)" name: only "word" characters are allowed.