mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-22 16:15:34 +08:00
PHP80 小修 (#187)
* migrate-php80 fix styles fix static analyse * fix some bugs
This commit is contained in:
@@ -11,7 +11,7 @@ class CheckConfigCommand extends Command
|
||||
{
|
||||
use SourceLoadModeOnly;
|
||||
|
||||
private $need_update = false;
|
||||
private bool $need_update = false;
|
||||
|
||||
protected function handle(): int
|
||||
{
|
||||
|
||||
@@ -130,9 +130,7 @@ class InitCommand extends Command
|
||||
// TODO: 优化代码,避免在循环中使用 array_merge 以减少资源消耗
|
||||
$files = array_merge($files, glob($this->getVendorPath($pattern), GLOB_BRACE));
|
||||
}
|
||||
return array_map(function ($file) {
|
||||
return str_replace($this->getVendorPath(''), '', $file);
|
||||
}, $files);
|
||||
return array_map(fn ($file) => str_replace($this->getVendorPath(''), '', $file), $files);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -143,7 +143,7 @@ class ProxyServerCommand extends Command
|
||||
$ip = 0;
|
||||
for ($i = 0; $i < 4; ++$i) {
|
||||
// var_dump(ord($tmp[$i]));
|
||||
$ip += ord($tmp[$i]) * pow(256, 3 - $i);
|
||||
$ip += ord($tmp[$i]) * 256 ** (3 - $i);
|
||||
}
|
||||
$request['dest_addr'] = long2ip($ip);
|
||||
$offset += 4;
|
||||
@@ -308,6 +308,7 @@ class ProxyServerCommand extends Command
|
||||
|
||||
public function udpWorkerOnMessage($udp_connection, $data, &$worker)
|
||||
{
|
||||
$addr = [];
|
||||
logger()->debug('send:' . bin2hex($data));
|
||||
$request = [];
|
||||
$offset = 0;
|
||||
@@ -326,7 +327,7 @@ class ProxyServerCommand extends Command
|
||||
$tmp = substr($data, $offset, 4);
|
||||
$ip = 0;
|
||||
for ($i = 0; $i < 4; ++$i) {
|
||||
$ip += ord($tmp[$i]) * pow(256, 3 - $i);
|
||||
$ip += ord($tmp[$i]) * 256 ** (3 - $i);
|
||||
}
|
||||
$request['dest_addr'] = long2ip($ip);
|
||||
$offset += 4;
|
||||
@@ -412,15 +413,11 @@ class ProxyServerCommand extends Command
|
||||
$this->config['auth'] = [0 => true];
|
||||
$type = $input->getOption('type') ?? 'http';
|
||||
logger()->notice('Proxy server started at ' . $type . '://' . $address . ':' . $port);
|
||||
switch ($type) {
|
||||
case 'http':
|
||||
$this->startHttpProxy($address, $port);
|
||||
break;
|
||||
case 'socks':
|
||||
case 'socks5':
|
||||
$this->startSocksProxy($address, $port);
|
||||
break;
|
||||
}
|
||||
match ($type) {
|
||||
'http' => $this->startHttpProxy($address, $port),
|
||||
'socks', 'socks5' => $this->startSocksProxy($address, $port),
|
||||
default => 0,
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -464,7 +461,7 @@ class ProxyServerCommand extends Command
|
||||
* @param string $address 地址
|
||||
* @param int|string $port 端口
|
||||
*/
|
||||
private function startSocksProxy(string $address, $port)
|
||||
private function startSocksProxy(string $address, int|string $port)
|
||||
{
|
||||
define('STAGE_INIT', 0);
|
||||
define('STAGE_AUTH', 1);
|
||||
|
||||
@@ -21,9 +21,7 @@ class ServerStartCommand extends ServerCommand
|
||||
{
|
||||
$cmd = new self();
|
||||
$cmd->configure();
|
||||
return array_map(function ($x) {
|
||||
return $x->getDefault();
|
||||
}, $cmd->getDefinition()->getOptions());
|
||||
return array_map(fn ($x) => $x->getDefault(), $cmd->getDefinition()->getOptions());
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
|
||||
@@ -33,7 +33,7 @@ class ServerStopCommand extends ServerCommand
|
||||
$pid = file_get_contents($file_path . '/' . $file);
|
||||
Process::kill((int) $pid, SIGKILL);
|
||||
} elseif ($file === 'master.json') {
|
||||
$json = json_decode(file_get_contents($file_path . '/' . $file), true);
|
||||
$json = json_decode(file_get_contents($file_path . '/' . $file), true, 512, JSON_THROW_ON_ERROR);
|
||||
Process::kill($json['pid'], SIGKILL);
|
||||
}
|
||||
unlink($file_path . '/' . $file);
|
||||
|
||||
Reference in New Issue
Block a user