value('value'); } catch (\Throwable $error) { error_log('Unable to read the network-line feature switch: ' . get_class($error)); return self::$cached = false; } return self::$cached = self::valueIsEnabled($value); } /** Call only inside a database transaction before locking region rows. */ public static function lockedEnabled(): bool { $row = Configurations::where('name', self::CONFIG_KEY) ->lockForUpdate()->first(); if ($row === null) { throw new CloudError( '线路功能配置未初始化,请先执行 cloudInit', 500 ); } return self::valueIsEnabled($row->value); } public static function allowsLine(bool $isDefault): bool { return self::enabled() || $isDefault; } public static function save(bool $enabled): void { $row = Configurations::where('name', self::CONFIG_KEY)->first(); if ($row === null) { $row = new Configurations(); $row->name = self::CONFIG_KEY; } $row->value = $enabled ? 'true' : 'false'; $row->save(); self::$cached = $enabled; } private static function valueIsEnabled($value): bool { return in_array(strtolower(trim((string) $value)), ['1', 'true', 'yes', 'on'], true); } }