app/models/Setting.php
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
<?php
require_once __DIR__ . '/../../core/BaseModel.php';
class Setting extends BaseModel {
protected $table = 'settings';
protected $fillable = ['key', 'value', 'type', 'group', 'description'];
protected $primaryKey = 'id';
protected $timestamps = true;
private static $cache = null;
public function getAllSettings() {
if (self::$cache !== null) {
return self::$cache;
}
$settings = $this->findAll();
$result = [];
foreach ($settings as $setting) {
$value = $setting['value'];
switch ($setting['type']) {
case 'int':
case 'integer':
$value = (int)$value;
break;
case 'bool':
case 'boolean':
$value = $value === '1' || $value === 'true';
break;
case 'array':
case 'json':
$value = json_decode($value, true);
break;
}
$result[$setting['key']] = $value;
}
self::$cache = $result;
return $result;
}
public function get($key, $default = null) {
$settings = $this->getAllSettings();
return $settings[$key] ?? $default;
}
public function set($key, $value) {
$setting = $this->findOneBy('key', $key);
if (is_array($value)) {
$value = json_encode($value, JSON_UNESCAPED_UNICODE);
$type = 'json';
} elseif (is_bool($value)) {
$value = $value ? '1' : '0';
$type = 'bool';
} elseif (is_int($value)) {
$type = 'int';
后面还有 35 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。
