1
0

first commit

This commit is contained in:
2020-08-06 14:58:51 +08:00
commit 17096657dc
780 changed files with 92857 additions and 0 deletions

71
extend/tools/Config.php Normal file
View File

@@ -0,0 +1,71 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace tools;
use think\Cache;
use think\Config as Conf;
use think\Db;
/**
* 加载系统配置,依赖数据库和缓存
*/
class Config
{
/**
* 加载系统扩展配置
*/
public static function load()
{
$config = Cache::get('db_config_cache_data');
if (!$config) {
$data = Db::name('Config')->where('status', 1)->field('type,name,value')->select();
$config = [];
if ($data && is_array($data)) {
foreach ($data as $value) {
$config[$value['name']] = self::parse($value['type'], $value['value']);
}
}
Cache::set('db_config_cache_data', $config);
}
Conf::set($config);
}
/**
* 根据配置类型解析配置
* @param integer $type 配置类型
* @param string $value 配置值
* @return array
*/
private static function parse($type, $value)
{
switch ($type) {
case 3: //解析数组
$array = preg_split('/[\r\n]+/', trim($value, "\r\n"));
if (strpos($value, ':')) {
$value = [];
foreach ($array as $val) {
list($k, $v) = explode(':', $val, 2);
$value[$k] = $v;
}
} else {
$value = $array;
}
break;
}
return $value;
}
/**
* 清除配置缓存
*/
public static function clear()
{
Cache::rm('db_config_cache_data');
}
}