mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-14 19:40:53 +08:00
fix: resolve PHPStan static analysis warnings
This commit is contained in:
@@ -11,7 +11,7 @@ class SingBox implements ProtocolInterface
|
||||
private $user;
|
||||
private $config;
|
||||
|
||||
public function __construct($user, $servers, array $options = null)
|
||||
public function __construct($user, $servers)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->servers = $servers;
|
||||
@@ -84,6 +84,14 @@ class SingBox implements ProtocolInterface
|
||||
$tuicConfig = $this->buildTuic($this->user['uuid'], $item);
|
||||
$proxies[] = $tuicConfig;
|
||||
}
|
||||
if ($item['type'] === 'socks') {
|
||||
$socksConfig = $this->buildSocks($this->user['uuid'], $item);
|
||||
$proxies[] = $socksConfig;
|
||||
}
|
||||
if ($item['type'] === 'http') {
|
||||
$httpConfig = $this->buildHttp($this->user['uuid'], $item);
|
||||
$proxies[] = $httpConfig;
|
||||
}
|
||||
}
|
||||
foreach ($outbounds as &$outbound) {
|
||||
if (in_array($outbound['type'], ['urltest', 'selector'])) {
|
||||
@@ -361,4 +369,58 @@ class SingBox implements ProtocolInterface
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
protected function buildSocks($password, $server): array
|
||||
{
|
||||
$protocol_settings = data_get($server, 'protocol_settings', []);
|
||||
$array = [
|
||||
'type' => 'socks',
|
||||
'tag' => $server['name'],
|
||||
'server' => $server['host'],
|
||||
'server_port' => $server['port'],
|
||||
'version' => '5', // 默认使用 socks5
|
||||
'username' => $password,
|
||||
'password' => $password,
|
||||
];
|
||||
|
||||
if (data_get($protocol_settings, 'udp_over_tcp')) {
|
||||
$array['udp_over_tcp'] = true;
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
protected function buildHttp($password, $server): array
|
||||
{
|
||||
$protocol_settings = data_get($server, 'protocol_settings', []);
|
||||
$array = [
|
||||
'type' => 'http',
|
||||
'tag' => $server['name'],
|
||||
'server' => $server['host'],
|
||||
'server_port' => $server['port'],
|
||||
'username' => $password,
|
||||
'password' => $password,
|
||||
];
|
||||
|
||||
if ($path = data_get($protocol_settings, 'path')) {
|
||||
$array['path'] = $path;
|
||||
}
|
||||
|
||||
if ($headers = data_get($protocol_settings, 'headers')) {
|
||||
$array['headers'] = $headers;
|
||||
}
|
||||
|
||||
if (data_get($protocol_settings, 'tls')) {
|
||||
$array['tls'] = [
|
||||
'enabled' => true,
|
||||
'insecure' => (bool) data_get($protocol_settings, 'tls_settings.allow_insecure', false),
|
||||
];
|
||||
|
||||
if ($serverName = data_get($protocol_settings, 'tls_settings.server_name')) {
|
||||
$array['tls']['server_name'] = $serverName;
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user