示例#1
0
文件: Config.php 项目: kangkot/bldr
 /**
  * @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)));
     }
 }
示例#2
0
 public function testGetThirdPartyBlocks()
 {
     $embeddedComposer = $this->getMockBuilder('Dflydev\\EmbeddedComposer\\Core\\EmbeddedComposer')->disableOriginalConstructor()->getMock();
     $config = $this->getMockBuilder('Composer\\Config')->disableOriginalConstructor()->getMock();
     $config->expects($this->once())->method('has')->with('block-loader')->willReturn(true);
     $config->expects($this->once())->method('get')->with('block-loader')->willReturn('build/blocks.yml');
     $embeddedComposer->expects($this->once())->method('getExternalComposerConfig')->willReturn($config);
     $embeddedComposer->expects($this->once())->method('getExternalRootDirectory')->willReturn(vfsStream::url('root'));
     $this->application->expects($this->once())->method('getEmbeddedComposer')->willReturn($embeddedComposer);
     $bldrFolder = vfsStream::newDirectory('build')->at($this->root);
     vfsStream::newFile('blocks.yml')->withContent('[ \\stdClass, \\stdClass ]')->at($bldrFolder);
     $this->containerBuilder = new ContainerBuilder($this->application, $this->input, $this->output);
     $this->assertCount(2, $this->containerBuilder->getThirdPartyBlocks());
 }