Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
0
 /**
  * Separate YAML front matter from content and set options,
  * then return the remaining content.
  *
  * @param string $source The source text
  *
  * @return string The rest of the file content
  */
 private function parseFrontMatter($source)
 {
     $parts = preg_split('/[\\n]*[-]{3}[\\n]/', $source, 3);
     // If there's only one item in the array, or the first item isn't empty,
     // then there isn't any YAML front matter, and we can just process the
     // source file in it's raw form
     if (count($parts) === 1 || !empty($parts[0])) {
         return $source;
     }
     list(, $yaml, $content) = $parts;
     $options = Yaml::parse($yaml);
     foreach ($options as $key => $value) {
         if (array_key_exists($key, static::$defaultOptions)) {
             $this->setOption($key, $value);
             continue;
         }
         $this->addVar($key, $value);
     }
     return $content;
 }