예제 #1
0
 /**
  * Load a config directory
  *
  * @param string $dir
  * @return object
  */
 public function load($dir)
 {
     if (!is_dir($dir)) {
         if (empty($this->options['optional'])) {
             trigger_error("Config directory '{$dir}' doesn't exist", E_USER_WARNING);
         }
         return null;
     }
     $config = (object) array();
     foreach (scandir($dir) as $file) {
         if ($file[0] == '.') {
             continue;
         }
         if (is_dir("{$dir}/{$file}")) {
             $data = $this->load("{$dir}/{$file}");
         } else {
             $loader = Config::getLoader("{$dir}/{$file}", $this->options);
             if (!$loader) {
                 continue;
             }
             $data = $loader->load("{$dir}/{$file}");
         }
         if ($data) {
             $key = pathinfo($file, PATHINFO_FILENAME);
             Config::merge($config->{$key}, $data);
         }
     }
     return $config;
 }
예제 #2
0
 /**
  * Load all files in a directory
  *
  * @param string $dir
  * @return object
  */
 protected function loadDir($dir)
 {
     $exts = array_keys(Config::$loaders, get_called_class());
     if (empty($exts)) {
         return null;
     }
     $glob = '*.' . (count($exts) == 1 ? reset($exts) : '{' . join(',', $exts) . '}');
     $config = (object) array();
     foreach (glob("{$dir}/{$glob}", GLOB_BRACE) as $file) {
         if (basename($file)[0] == '.') {
             continue;
         }
         $key = pathinfo($file, PATHINFO_FILENAME);
         $data = $this->load($file);
         if ($data) {
             Config::merge($config->{$key}, $data);
         }
     }
     return $config;
 }