Esempio n. 1
0
 /**
  * Load and store the application config.
  *
  * @return Config
  */
 private function loadConfig()
 {
     $base = APP_ROOT . 'config/';
     $filename = $base . 'app.yaml';
     if (!file_exists($filename)) {
         throw new ConfigNotFoundException('The application config file ' . $filename . ' could not be found');
     }
     $config = Yaml::parseFile($filename);
     // Populate the environments array
     $hostname = gethostname();
     $environments = Yaml::parseFile($base . 'env.yaml');
     foreach ($environments as $env => $hosts) {
         foreach ($hosts as $host) {
             if (fnmatch($host, $hostname)) {
                 $this->environments[] = $env;
                 // Merge the app config for the environment
                 $filename = $base . $env . '/app.yaml';
                 if (file_exists($filename)) {
                     $envConfig = Yaml::parseFile($filename);
                     $config = array_merge($config, $envConfig);
                 }
             }
         }
     }
     // Loop through each of the config files and add them
     // to the main config array
     foreach (glob(APP_ROOT . 'config/*.yaml') as $file) {
         $key = str_replace('.yaml', '', basename($file));
         $config[$key] = Yaml::parseFile($file);
         // Loop through each of the environments and merge their config
         foreach ($this->environments as $env) {
             $filename = $base . $env . '/' . $key . '.yaml';
             if (file_exists($filename)) {
                 $envConfig = Yaml::parseFile($filename);
                 $config[$key] = array_merge($config[$key], $envConfig);
             }
         }
     }
     // Create and store the config object
     return $this->config = new Config($config);
 }
Esempio n. 2
0
 /**
  * Load and store the application config.
  *
  * @return Config
  */
 private function loadConfig()
 {
     $config = [];
     // Loop through each of the config files and add them
     // to the main config array
     foreach (glob(APP_ROOT . 'config' . DS . '*.yaml') as $file) {
         $key = str_replace('.yaml', '', basename($file));
         $config[$key] = Yaml::parseFile($file);
     }
     // Create and store the config object
     return $this->config = new Config($config);
 }