コード例 #1
0
 public function testCompileWithoutDefinitions()
 {
     $manager = $this->getMock('Affiniti\\Config\\ConfigManager');
     $file1 = new ConfigFile('file1.yml', 'config');
     $file2 = new ConfigFile('file1.php', 'config');
     $manager->expects($this->any())->method('getFiles')->willReturn([$file1, $file2]);
     $manager->expects($this->any())->method('getDefinitions')->willReturn([]);
     $config1 = array('test' => ['value' => 1, 'other' => 2]);
     $config2 = array('test' => ['value' => 2, 'merge' => 3], 'merge' => true);
     $result = array('config' => ['test' => ['value' => [1, 2], 'other' => 2, 'merge' => 3], 'merge' => true]);
     $returnMap = array(['file1.yml', null, $config1], ['file1.php', null, $config2]);
     $mockLoader = $this->getMockLoaderFactory(2, $returnMap);
     // Load 2 files - process 0 against definitions.
     $compiler = new ConfigCompiler($manager, $mockLoader, $this->getMockProcessor(0), $this->getMockCacheFactory());
     try {
         $config = $compiler->compile();
         $this->assertTrue($result == $config);
     } catch (ConfigException $ex) {
         $this->fail('Exception raised: ' . $ex->getMessage());
     }
 }
コード例 #2
0
 private function setupConfig(\Silex\Application $app, $configName)
 {
     $app[$configName . '.manager'] = $app->share(function ($app) {
         return new ConfigManager();
     });
     $app[$configName] = $app->share(function ($app) use($configName) {
         // Get the config paths and the file locator.
         $paths = $app[$configName . '.paths'];
         if (null === $paths || count($paths) === 0) {
             throw ConfigException::pathsNotSpecified();
         }
         $locator = new FileLocator($paths);
         // Dispatch the event so that other providers can add their
         // definitions.
         $this->dispatchInitEvent($app);
         // Get some app definitions.
         $cacheType = $app[$this->configName . '.cache.type'];
         $manager = $app[$configName . '.manager'];
         $loaderFactory = new LoaderFactory($locator, $manager->getLoaders());
         $cacheFactory = new CacheProducer($manager->getCacheFactories(), $app, $cacheType);
         $processor = new Processor();
         $compiler = new ConfigCompiler($manager, $loaderFactory, $processor, $cacheFactory);
         // Run the configuration compiler.
         $config = new Config($compiler->compile());
         $this->dispatchLoadedEvent($app, $config);
         return $config;
     });
 }