Kaynağa Gözat

[DependencyInjection] fix 2219 IniFileLoader accept Boolean

stealth35 13 yıl önce
ebeveyn
işleme
11c441289a

+ 6 - 1
src/Symfony/Component/DependencyInjection/Loader/IniFileLoader.php

@@ -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);
             }
         }

+ 4 - 0
tests/Symfony/Tests/Component/DependencyInjection/Fixtures/ini/boolean.ini

@@ -0,0 +1,4 @@
+[parameters]
+  foo = true
+  bar = False
+  boo = NULL

+ 5 - 0
tests/Symfony/Tests/Component/DependencyInjection/Loader/IniFileLoaderTest.php

@@ -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');