I'm having problems to define a boolean parameter in parameters.ini
file. This is the definition:
aParameter = true
Then, in config.yml
I do:
aParameter: %aParameter%
But I'm getting this error:
InvalidTypeException: Invalid type for path "myService.aParameter". Expected boolean, but got string.
This error disappears when I replace %aParameter%
with true
. What am I doing wrong?
Default Symfony2 import parameters in YAML format, so one of first line should be:
imports:
- { resource: parameters.yml }
And in parameters.yml use:
aParameter: true
I dont use INI files, so i dont know how it works.
Symfony 2 uses parse_ini_file() function and it does not seem to return the right type for boolean value.
<?php
file_put_contents('test.ini', "test1=on\ntest2=true\ntest3=1");
var_dump(parse_ini_file('test.ini'));
will output
array(3) {
'test1' => string(1) "1"
'test2' => string(1) "1"
'test3' => string(1) "1"
}
You might want to implement your own ini
parser taking Symfony\Component\DependencyInjection\Loader\IniFileLoader
as an example.
Example of lexer that supports booleans can be found in comments at php doc for parse_ini_file()
An alternative would be to use the yaml format for your configuration file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With