Example #1
0
 /**
  * @covers Symfony\Component\DependencyInjection\Loader\IniFileLoader::__construct
  * @covers Symfony\Component\DependencyInjection\Loader\IniFileLoader::load
  */
 public function testLoader()
 {
     $container = new ContainerBuilder();
     $loader = new IniFileLoader($container, self::$fixturesPath . '/ini');
     $loader->load('parameters.ini');
     $this->assertEquals(array('foo' => 'bar', 'bar' => '%foo%'), $container->getParameterBag()->all(), '->load() takes a single file name as its first argument');
     try {
         $loader->load('foo.ini');
         $this->fail('->load() throws an InvalidArgumentException if the loaded file does not exist');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file does not exist');
         $this->assertStringStartsWith('The file "foo.ini" does not exist (in: ', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file does not exist');
     }
     try {
         @$loader->load('nonvalid.ini');
         $this->fail('->load() throws an InvalidArgumentException if the loaded file is not parseable');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file is not parseable');
         $this->assertEquals('The nonvalid.ini file is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file is not parseable');
     }
 }
Example #2
0
 /**
  * Registers a new plugin from a directory.
  * @param  \Symfony\Component\Finder\SplFileInfo $pluginClassPath
  * @throws \Exception
  */
 protected function registerPlugin(SplFileInfo $pluginClassPath)
 {
     $pluginName = preg_replace('/Plugin\\.php$/', '', $pluginClassPath->getFilename());
     $pluginClass = sprintf('Ladybug\\Plugin\\%s\\%sPlugin', $pluginName, $pluginName);
     $file = $pluginClass::getConfigFile();
     $extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
     $dir = pathinfo($file, PATHINFO_DIRNAME);
     $filename = pathinfo($file, PATHINFO_FILENAME);
     switch ($extension) {
         case 'xml':
             $loader = new Loader\XmlFileLoader($this->container, new FileLocator($dir));
             break;
         case 'yml':
             $loader = new Loader\YamlFileLoader($this->container, new FileLocator($dir));
             break;
         case 'php':
             $loader = new Loader\PhpFileLoader($this->container, new FileLocator($dir));
             break;
         case 'ini':
             $loader = new Loader\IniFileLoader($this->container, new FileLocator($dir));
             break;
         default:
             throw new \Exception('Invalid config file');
     }
     $loader->load($filename . '.' . $extension);
     // helpers
     $this->container->setParameter('helpers', array_merge($this->container->getParameter('helpers'), $pluginClass::registerHelpers()));
 }