refactor(singbox): use data_get for array access

This commit is contained in:
xboard
2025-08-23 11:19:37 +08:00
parent a907ef523c
commit af747c61cc
+7 -7
View File
@@ -351,7 +351,7 @@ class SingBox extends AbstractProtocol
'tag' => $server['name'], 'tag' => $server['name'],
'tls' => [ 'tls' => [
'enabled' => true, 'enabled' => true,
'insecure' => (bool) $protocol_settings['tls']['allow_insecure'], 'insecure' => (bool) data_get($protocol_settings, 'tls.allow_insecure', false),
] ]
]; ];
// 支持 1.11.0 版本及以上 `server_ports` 和 `hop_interval` 配置 // 支持 1.11.0 版本及以上 `server_ports` 和 `hop_interval` 配置
@@ -368,22 +368,22 @@ class SingBox extends AbstractProtocol
$baseConfig['tls']['server_name'] = $serverName; $baseConfig['tls']['server_name'] = $serverName;
} }
$speedConfig = [ $speedConfig = [
'up_mbps' => $protocol_settings['bandwidth']['up'], 'up_mbps' => data_get($protocol_settings, 'bandwidth.up'),
'down_mbps' => $protocol_settings['bandwidth']['down'], 'down_mbps' => data_get($protocol_settings, 'bandwidth.down'),
]; ];
$versionConfig = match (data_get($protocol_settings, 'version', 1)) { $versionConfig = match (data_get($protocol_settings, 'version', 1)) {
2 => [ 2 => [
'type' => 'hysteria2', 'type' => 'hysteria2',
'password' => $password, 'password' => $password,
'obfs' => $protocol_settings['obfs']['open'] ? [ 'obfs' => data_get($protocol_settings, 'obfs.open') ? [
'type' => $protocol_settings['obfs']['type'], 'type' => data_get($protocol_settings, 'obfs.type'),
'password' => $protocol_settings['obfs']['password'] 'password' => data_get($protocol_settings, 'obfs.password')
] : null, ] : null,
], ],
default => [ default => [
'type' => 'hysteria', 'type' => 'hysteria',
'auth_str' => $password, 'auth_str' => $password,
'obfs' => $protocol_settings['obfs']['password'], 'obfs' => data_get($protocol_settings, 'obfs.password'),
'disable_mtu_discovery' => true, 'disable_mtu_discovery' => true,
] ]
}; };