From 4ebb7e96860a2923f1d2086f20ade9ad7632325e Mon Sep 17 00:00:00 2001 From: whwyy Date: Tue, 12 Dec 2023 10:56:42 +0800 Subject: [PATCH] eee --- Abstracts/AsyncServer.php | 1 - Handler/OnRequest.php | 1 - Handler/OnServer.php | 5 ++--- HotReload.php | 11 ++++++----- ServerCommand.php | 7 ++++--- ServerProviders.php | 1 - State.php | 3 ++- Task/Task.php | 3 ++- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Abstracts/AsyncServer.php b/Abstracts/AsyncServer.php index a2c4ca0..70e45f1 100644 --- a/Abstracts/AsyncServer.php +++ b/Abstracts/AsyncServer.php @@ -3,7 +3,6 @@ namespace Kiri\Server\Abstracts; use Exception; -use Kiri; use Kiri\Exception\ConfigException; use Kiri\Exception\NotFindClassException; use Kiri\Server\Config as SConfig; diff --git a/Handler/OnRequest.php b/Handler/OnRequest.php index ede38a8..d5dc8c4 100644 --- a/Handler/OnRequest.php +++ b/Handler/OnRequest.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace Kiri\Server\Handler; use Exception; -use Kiri; use Kiri\Di\Inject\Container; use Kiri\Di\Context; use Kiri\Di\Interface\ResponseEmitterInterface; diff --git a/Handler/OnServer.php b/Handler/OnServer.php index 6719fed..573cb76 100644 --- a/Handler/OnServer.php +++ b/Handler/OnServer.php @@ -2,10 +2,9 @@ namespace Kiri\Server\Handler; +use Kiri; use Kiri\Di\Inject\Container; use Kiri\Error\StdoutLogger; -use Psr\Container\ContainerExceptionInterface; -use Psr\Container\NotFoundExceptionInterface; use Psr\Log\LoggerInterface; use ReflectionException; use Kiri\Server\Abstracts\Server; @@ -36,7 +35,7 @@ class OnServer extends Server */ public function onStart(SServer $server): void { - \Kiri::setProcessName(sprintf('start[%d].server', $server->master_pid)); + Kiri::setProcessName(sprintf('start[%d].server', $server->master_pid)); foreach (config('server.ports') as $value) { $this->logger->alert('Listen ' . $value['type'] . ' address ' . $value['host'] . '::' . $value['port']); } diff --git a/HotReload.php b/HotReload.php index 1ebc865..bd8fcd5 100644 --- a/HotReload.php +++ b/HotReload.php @@ -45,7 +45,8 @@ class HotReload extends BaseProcess */ public function getName(): string { - return '[' . \config('id', 'system-service') . '].hot.load'; // TODO: Change the autogenerated stub + // TODO: Change the autogenerated stub + return '[' . \config('id', 'system-service') . '].hot.load'; } @@ -123,7 +124,7 @@ class HotReload extends BaseProcess $this->watch(rtrim($dir, '/')); } Event::add($this->inotify, fn() => $this->check()); - Event::cycle(fn() => function() { + Event::cycle(fn() => function () { Event::dispatch(); }, true); Event::wait(); @@ -204,7 +205,7 @@ class HotReload extends BaseProcess */ private function checkFile($value, $isReload): bool { - $md5 = md5($value); + $md5 = md5($value); $mTime = filectime($value); if (!isset($this->md5Map[$md5])) { if ($isReload) { @@ -341,7 +342,7 @@ class HotReload extends BaseProcess return FALSE; } - $wd = @inotify_add_watch($this->inotify, $dir, IN_MODIFY | IN_DELETE | IN_CREATE | IN_MOVE); + $wd = @inotify_add_watch($this->inotify, $dir, IN_MODIFY | IN_DELETE | IN_CREATE | IN_MOVE); $this->watchFiles[$dir] = $wd; $files = scandir($dir); @@ -358,7 +359,7 @@ class HotReload extends BaseProcess //检测文件类型 if (strstr($f, '.') == '.php') { - $wd = @inotify_add_watch($this->inotify, $path, IN_MODIFY | IN_DELETE | IN_CREATE | IN_MOVE); + $wd = @inotify_add_watch($this->inotify, $path, IN_MODIFY | IN_DELETE | IN_CREATE | IN_MOVE); $this->watchFiles[$path] = $wd; } } diff --git a/ServerCommand.php b/ServerCommand.php index d9f32b6..789c9ba 100644 --- a/ServerCommand.php +++ b/ServerCommand.php @@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use function config; defined('ROUTER_TYPE_HTTP') or define('ROUTER_TYPE_HTTP', 'http'); defined('PID_PATH') or define('PID_PATH', APP_PATH . 'storage/server.pid'); @@ -99,7 +100,7 @@ class ServerCommand extends Command */ protected function stop(): int { - $configs = \config('server', []); + $configs = config('server', []); $instances = $this->manager->sortService($configs['ports'] ?? []); foreach ($instances as $config) { $this->state->exit($config->port); @@ -117,13 +118,13 @@ class ServerCommand extends Command protected function start(InputInterface $input): int { $daemon = (int)$input->getOption('daemon'); - if (\config('reload.hot', false) === true) { + if (config('reload.hot', false) === true) { $this->manager->addProcess(HotReload::class); } else { $this->router->scan_build_route(); } $this->manager->addProcess(config('processes', [])); - $this->manager->initCoreServers(\config('server', []), $daemon); + $this->manager->initCoreServers(config('server', []), $daemon); $this->manager->start(); return 1; } diff --git a/ServerProviders.php b/ServerProviders.php index a76fbfd..18a58d0 100644 --- a/ServerProviders.php +++ b/ServerProviders.php @@ -8,7 +8,6 @@ use Kiri\Abstracts\Providers; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use Symfony\Component\Console\Application; -use Kiri; /** * Class DatabasesProviders diff --git a/State.php b/State.php index aa4fe7a..d0e77b1 100644 --- a/State.php +++ b/State.php @@ -6,6 +6,7 @@ use Exception; use Kiri\Abstracts\Component; use Kiri\Server\Abstracts\TraitServer; use Swoole\Process; +use function config; class State extends Component { @@ -21,7 +22,7 @@ class State extends Component */ public function init(): void { - $this->servers = \config('server.ports'); + $this->servers = config('server.ports'); } diff --git a/Task/Task.php b/Task/Task.php index 5086de9..00d9496 100644 --- a/Task/Task.php +++ b/Task/Task.php @@ -3,6 +3,7 @@ namespace Kiri\Server\Task; +use Exception; use Kiri; use Kiri\Server\Constant; use ReflectionException; @@ -50,7 +51,7 @@ class Task * @param int $src_worker_id * @param mixed $data * @return mixed - * @throws ReflectionException + * @throws ReflectionException|Exception */ public function onTask(Server $server, int $task_id, int $src_worker_id, mixed $data): mixed {