Esempio n. 1
0
 public function configure()
 {
     $configuration = $this->loader->load();
     $config = new Config($this, $this->console);
     if (isset($configuration['providers'])) {
         foreach ($configuration['providers'] as $provider) {
             $config->configureProvider($provider);
         }
     }
     if (isset($configuration['settings'])) {
         $config->configureSettings($configuration['settings']);
     }
     if (isset($configuration['routes'])) {
         foreach ($configuration['routes'] as $routeName => $route) {
             $config->configureRoute($route, $routeName);
         }
     }
     if (isset($configuration['services'])) {
         foreach ($configuration['services'] as $serviceName => $service) {
             $config->configureService($serviceName, $service);
         }
     }
     if ($this->console != null && isset($configuration['console'])) {
         $consoleSettings = $configuration['console'];
         if (isset($consoleSettings['commands']) && is_array($consoleSettings['commands'])) {
             foreach ($consoleSettings['commands'] as $commandSetting) {
                 $config->configureCommand($commandSetting);
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * test loading a yaml constant file
  */
 public function testConstantLoading()
 {
     $randomValue = rand(0, 1000);
     $explicitConstant = 'explicit-' . $randomValue;
     $file1Constant = 'file1-' . $randomValue;
     $file2Constant = 'file2-' . $randomValue;
     $mockConfig = array('json' => json_encode(['EXPLICIT_CONSTANT' => '#EXPLICIT_CONSTANT#', 'FILE_CONSTANT_1' => '#FILE_CONSTANT_1#', 'FILE_CONSTANT_2' => '#FILE_CONSTANT_2#']));
     $mockFinder = $this->getMockFinder($mockConfig);
     $mockConstantLoader = $this->getMockBuilder('Skip\\AbstractConstantConfigLoaderInterface')->disableOriginalConstructor()->getMock();
     $mockConstantLoader->expects($this->exactly(2))->method('load')->will($this->returnCallback(function ($filePath) use($file1Constant, $file2Constant) {
         switch ($filePath) {
             case 'app-constants.yml':
                 return ['FILE_CONSTANT_1' => $file1Constant];
             case 'app-constants.yml.dist':
                 return ['FILE_CONSTANT_1' => 'THIS_VALUE_SHOULD_BE_OVERWRITTEN', 'FILE_CONSTANT_2' => $file2Constant];
         }
         throw new \Exception('This file does not exist!');
     }));
     $loader = new ConfigLoader(array('dir1'), $mockFinder);
     $loader->setConstantLoader($mockConstantLoader);
     $loader->setConstants(['EXPLICIT_CONSTANT' => $explicitConstant], 'app-constants.yml', 'app-constants.yml.dist');
     $config = $loader->load();
     $this->assertEquals(array('EXPLICIT_CONSTANT' => $explicitConstant, 'FILE_CONSTANT_1' => $file1Constant, 'FILE_CONSTANT_2' => $file2Constant), $config);
 }