[fix] CustomDevice

This commit is contained in:
Lkeme 2021-10-03 23:29:58 +08:00
parent fac9d3279e
commit 1eb4b692db
2 changed files with 20 additions and 8 deletions

1
.gitignore vendored
View File

@ -28,6 +28,7 @@ conf/user1.ini
/conf/test1.ini /conf/test1.ini
/src/backup/ /src/backup/
script.php script.php
ABOUT.md
task/* task/*
cache/* cache/*

View File

@ -23,22 +23,33 @@ class Device
private string $bili_file = 'bili.yaml'; private string $bili_file = 'bili.yaml';
private string $device_file = 'device.yaml'; private string $device_file = 'device.yaml';
/** /**
* 加载配置 * @use 真实路径
* @param string $file
* @return string
*/
private function fileRealPath(string $file): string
{
return APP_CONF_PATH . $file;
}
/**
* @use 加载配置
*/ */
public function load(string $load_file) public function load(string $load_file)
{ {
// 提前处理 后缀 // 提前处理 后缀
$custom_file = str_replace(strrchr($load_file, "."), "", $load_file) . '_'; $custom_file = str_replace(strrchr($load_file, "."), "", $load_file) . '_';
// 自定义客户端 // 自定义客户端
if (is_file(APP_CONF_PATH . $custom_file . $this->bili_file)) { if (is_file($this->fileRealPath($custom_file . $this->bili_file))) {
$this->bili_file = APP_CONF_PATH . $custom_file . $this->bili_file; $this->bili_file = $custom_file . $this->bili_file;
Log::info('使用自定义Bili.yaml'); Log::info('使用自定义' . $this->bili_file);
} }
// 自定义设备 // 自定义设备
if (is_file(APP_CONF_PATH . $custom_file . $this->device_file)) { if (is_file($this->fileRealPath($custom_file . $this->device_file))) {
$this->device_file = APP_CONF_PATH . $custom_file . $this->device_file; $this->device_file = $custom_file . $this->device_file;
Log::info('使用自定义Device.yaml'); Log::info('使用自定义' . $this->device_file);
} }
// 加载数据 // 加载数据
$this->device = new Config(); $this->device = new Config();
@ -47,7 +58,7 @@ class Device
$files = [$this->bili_file, $this->device_file]; $files = [$this->bili_file, $this->device_file];
// 循环加载 // 循环加载
foreach ($files as $file) { foreach ($files as $file) {
$processor->extend($loader->load(APP_CONF_PATH . $file)); $processor->extend($loader->load($this->fileRealPath($file)));
} }
$this->device->import($processor->export()); $this->device->import($processor->export());
} }