private function file_gen($arr_configSrc, $str_file, $is_install = false)
{
$_str_config = "";
$_str_constConfig = "";
if (file_exists($this->str_pathRoot . "config/" . $str_file . ".inc.php")) {
//如果文件存在
if ($is_install) {
//如果是安装状态,一一对比
include_once $this->str_pathRoot . "config/" . $str_file . ".inc.php";
//载入配置
$_arr_config = file($this->str_pathRoot . "config/" . $str_file . ".inc.php");
//将配置文件转换为数组
foreach ($arr_configSrc as $_key_m => $_value_m) {
if (!defined($_key_m)) {
//如不存在则加上
if ($_value_m[1] == "str") {
$_str_constConfig = "define(\"" . $_key_m . "\", \"" . $_value_m[0] . "\");" . PHP_EOL;
} else {
$_str_constConfig = "define(\"" . $_key_m . "\", " . $_value_m[0] . ");" . PHP_EOL;
}
array_push($_arr_config, $_str_constConfig);
}
}
foreach ($_arr_config as $_key_m => $_value_m) {
//拼接
$_str_config .= $_value_m;
}
$_str_config = preg_replace("/include_once\\(\\S+\\s\\.\\s\"\\S+\"\\);\n?/i", "", $_str_config);
if ($str_file == "config") {
//如果为全局配置,则增加 8 行
$_str_config = $this->end_process($_str_config);
}
//print_r($_str_config);
file_put_contents($this->str_pathRoot . "config/" . $str_file . ".inc.php", $_str_config);
}
} else {
//如果文件不存在则生成默认
$_str_config = "<?php" . PHP_EOL;
foreach ($arr_configSrc as $_key_m => $_value_m) {
if ($_value_m[1] == "str") {
$_str_config .= "define(\"" . $_key_m . "\", \"" . $_value_m[0] . "\");" . PHP_EOL;
} else {
$_str_config .= "define(\"" . $_key_m . "\", " . $_value_m[0] . ");" . PHP_EOL;
}
}
if ($str_file == "config") {
//如果为全局配置,则增加 8 行
$_str_config = $this->end_process($_str_config);
}
file_put_contents($this->str_pathRoot . "config/" . $str_file . ".inc.php", $_str_config);
}
}