2021-03-18 14:56:35 +08:00
|
|
|
<?php /** @noinspection PhpUnused */
|
2020-05-02 23:27:26 +08:00
|
|
|
|
|
|
|
|
|
2020-08-31 10:11:06 +08:00
|
|
|
namespace ZM\Utils;
|
2020-05-02 23:27:26 +08:00
|
|
|
|
|
|
|
|
|
2020-08-31 10:11:06 +08:00
|
|
|
use ZM\Config\ZMConfig;
|
2021-02-15 15:15:26 +08:00
|
|
|
use ZM\Console\Console;
|
2020-05-23 17:23:29 +08:00
|
|
|
|
2020-05-02 23:27:26 +08:00
|
|
|
class DataProvider
|
|
|
|
|
{
|
|
|
|
|
public static $buffer_list = [];
|
|
|
|
|
|
2021-03-18 14:56:35 +08:00
|
|
|
public static function getResourceFolder(): string {
|
2020-05-02 23:27:26 +08:00
|
|
|
return self::getWorkingDir() . '/resources/';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getWorkingDir() {
|
2021-02-09 17:09:09 +08:00
|
|
|
if (LOAD_MODE == 0) return WORKING_DIR;
|
2020-06-05 13:36:30 +08:00
|
|
|
elseif (LOAD_MODE == 1) return LOAD_MODE_COMPOSER_PATH;
|
|
|
|
|
elseif (LOAD_MODE == 2) return realpath('.');
|
|
|
|
|
return null;
|
2020-05-02 23:27:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getFrameworkLink() {
|
2020-08-31 10:11:06 +08:00
|
|
|
return ZMConfig::get("global", "http_reverse_link");
|
2020-05-02 23:27:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getDataFolder() {
|
|
|
|
|
return ZM_DATA;
|
|
|
|
|
}
|
2021-02-15 15:15:26 +08:00
|
|
|
|
|
|
|
|
public static function saveToJson($filename, $file_array) {
|
|
|
|
|
$path = ZMConfig::get("global", "config_dir");
|
|
|
|
|
$r = explode("/", $filename);
|
|
|
|
|
if(count($r) == 2) {
|
|
|
|
|
$path = $path . $r[0]."/";
|
|
|
|
|
if(!is_dir($path)) mkdir($path);
|
|
|
|
|
$name = $r[1];
|
|
|
|
|
} elseif (count($r) != 1) {
|
|
|
|
|
Console::warning("存储失败,文件名只能有一级目录");
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
$name = $r[0];
|
|
|
|
|
}
|
|
|
|
|
return file_put_contents($path.$name.".json", json_encode($file_array, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function loadFromJson($filename) {
|
|
|
|
|
$path = ZMConfig::get("global", "config_dir");
|
|
|
|
|
if(file_exists($path.$filename.".json")) {
|
|
|
|
|
return json_decode(file_get_contents($path.$filename.".json"), true);
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-02 23:27:26 +08:00
|
|
|
}
|