path = $path; $this->config = $init; $this->unique_key = $unique_key; } /** * 加载配置文件(多种格式) * @access public * @param string $file 配置文件名 * @param string $name 一级配置名 * @return array */ public function loadConfig(): array { $this->praseFiles($this->path); if(!empty($this->files)) { foreach ($this->files as $file) { $config = include $file; if(empty($this->config)) { $this->config = $config; }else{ if(!empty($config)) { if($this->unique_key) { $this->config = $this->config + $config; }else $this->config = array_merge($this->config, $config); } } } } return $this->config; } /** * 加载返回所有文件 */ public function loadFiles() { $this->praseFiles($this->path); return $this->files; } /** * 整理所有文件 * @param string $path */ protected function praseFiles(string $path) { $files = scandir($path); foreach ($files as $file) { if ($file != '.' && $file != '..') { if (is_dir($path . DIRECTORY_SEPARATOR . $file)) { $this->praseFiles($path . DIRECTORY_SEPARATOR . $file); } else { $this->files[] = $path . DIRECTORY_SEPARATOR . $file; } } } } }