Example #1
0
 /**
  * @param ContainerBuilder $container
  *
  * @throws Exception\ConfigurationFileNotFoundException
  * @throws \Exception
  */
 public static function read(ContainerBuilder $container)
 {
     /** @var InputInterface $input */
     $input = $container->get('input');
     $locations = [getcwd(), getcwd() . '/.bldr/'];
     if ($input->hasParameterOption('--global')) {
         $locations = array_merge($locations, [getenv('HOME'), getenv('HOME') . '/.bldr/']);
     }
     $locator = new FileLocator($locations);
     $resolver = new LoaderResolver([new Loader\YamlFileLoader($container, $locator), new Loader\XmlFileLoader($container, $locator), new Loader\PhpFileLoader($container, $locator), new Loader\IniFileLoader($container, $locator), new Loader\JsonFileLoader($container, $locator), new Loader\TomlFileLoader($container, $locator)]);
     $loader = new DelegatingLoader($resolver);
     $files = static::findFiles($input);
     $foundConfig = false;
     foreach ($files as $file) {
         try {
             $loader->load($file);
             $foundConfig = true;
         } catch (\Exception $e) {
             if (get_class($e) !== 'InvalidArgumentException') {
                 throw $e;
             }
         }
     }
     if (!$foundConfig) {
         throw new ConfigurationFileNotFoundException(sprintf("Either couldn't find the configuration file, or couldn't read it. " . "Make sure the extension is valid (%s). Tried: %s", implode(', ', static::$TYPES), implode(', ', $files)));
     }
 }