[DependencyInjection] fix 2219 IniFileLoader accept Boolean
This commit is contained in:
parent
545cd4cd63
commit
11c441289a
@ -35,13 +35,18 @@ class IniFileLoader extends FileLoader
|
||||
|
||||
$this->container->addResource(new FileResource($path));
|
||||
|
||||
$result = parse_ini_file($path, true);
|
||||
$result = parse_ini_file($path, true, INI_SCANNER_RAW);
|
||||
if (false === $result || array() === $result) {
|
||||
throw new \InvalidArgumentException(sprintf('The "%s" file is not valid.', $file));
|
||||
}
|
||||
|
||||
if (isset($result['parameters']) && is_array($result['parameters'])) {
|
||||
foreach ($result['parameters'] as $key => $value) {
|
||||
switch (strtolower($value)) {
|
||||
case 'true' : $value = true ; break;
|
||||
case 'false': $value = false; break;
|
||||
case 'null' : $value = null ; break;
|
||||
}
|
||||
$this->container->setParameter($key, $value);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,4 @@
|
||||
[parameters]
|
||||
foo = true
|
||||
bar = False
|
||||
boo = NULL
|
@ -35,6 +35,11 @@ class IniFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$loader->load('parameters.ini');
|
||||
$this->assertEquals(array('foo' => 'bar', 'bar' => '%foo%'), $container->getParameterBag()->all(), '->load() takes a single file name as its first argument');
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$loader = new IniFileLoader($container, new FileLocator(self::$fixturesPath.'/ini'));
|
||||
$loader->load('boolean.ini');
|
||||
$this->assertEquals(array('foo' => true, 'bar' => false, 'boo' => null), $container->getParameterBag()->all());
|
||||
|
||||
try {
|
||||
$loader->load('foo.ini');
|
||||
$this->fail('->load() throws an InvalidArgumentException if the loaded file does not exist');
|
||||
|
Reference in New Issue
Block a user