From c5b370dabcfd34602f8e143eefacaf552d5a15a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Thu, 2 Sep 2021 13:59:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/Abstracts/BaseApplication.php | 2 +- core/Abstracts/TraitApplication.php | 2 +- core/Application.php | 6 +-- {http-helper => http-server}/Server.php | 4 +- .../ServerCommand.php | 48 +++++++++---------- .../ServerProviders.php | 4 +- 6 files changed, 31 insertions(+), 35 deletions(-) rename {http-helper => http-server}/Server.php (97%) rename http-helper/Command.php => http-server/ServerCommand.php (63%) rename {http-helper => http-server}/ServerProviders.php (87%) diff --git a/core/Abstracts/BaseApplication.php b/core/Abstracts/BaseApplication.php index 060fa29d..6fe404b9 100644 --- a/core/Abstracts/BaseApplication.php +++ b/core/Abstracts/BaseApplication.php @@ -17,7 +17,7 @@ use Http\Context\HttpHeaders; use Http\Context\HttpParams; use Http\Context\Response; use Http\Route\Router; -use Http\Server; +use Server\Server; use Http\Shutdown; use JetBrains\PhpStorm\Pure; use Kafka\KafkaProvider; diff --git a/core/Abstracts/TraitApplication.php b/core/Abstracts/TraitApplication.php index 11753207..e7498f9a 100644 --- a/core/Abstracts/TraitApplication.php +++ b/core/Abstracts/TraitApplication.php @@ -11,7 +11,7 @@ use Http\Client\Curl; use Http\Context\Response; use Http\HttpFilter; use Http\Route\Router; -use Http\Server; +use Server\Server; use Http\Shutdown; use Kiri\Crontab\Producer; use Kiri\Async; diff --git a/core/Application.php b/core/Application.php index 4e0da07a..6b2a6283 100644 --- a/core/Application.php +++ b/core/Application.php @@ -15,9 +15,9 @@ use Console\Console; use Console\ConsoleProviders; use Database\DatabasesProviders; use Exception; -use Http\Command; +use Server\ServerCommand; use Http\Context\Response; -use Http\ServerProviders; +use Server\ServerProviders; use Kiri\Abstracts\BaseApplication; use Kiri\Abstracts\Config; use Kiri\Abstracts\Kernel; @@ -240,7 +240,7 @@ class Application extends BaseApplication */ private function enableFileChange($class): void { - if (!($class instanceof Command)) { + if (!($class instanceof ServerCommand)) { scan_directory(directory('app'), 'App'); } } diff --git a/http-helper/Server.php b/http-server/Server.php similarity index 97% rename from http-helper/Server.php rename to http-server/Server.php index 5af2c4fe..76393c41 100644 --- a/http-helper/Server.php +++ b/http-server/Server.php @@ -1,7 +1,7 @@ getServer(); - $manager->setDaemon($input->getArgument('daemon')); - if (!in_array($input->getArgument('action'), self::ACTIONS)) { - $output->write('I don\'t know what I want to do.'); + try { + $manager = Kiri::app()->getServer(); + $manager->setDaemon($input->getArgument('daemon')); + if (!in_array($input->getArgument('action'), self::ACTIONS)) { + throw new Exception('I don\'t know what I want to do.'); + } + if ($manager->isRunner() && $input->getArgument('action') == 'start') { + throw new Exception('Service is running. Please use restart.'); + } + $manager->shutdown(); + if ($input->getArgument('action') == 'stop') { + throw new Exception('shutdown success'); + } + $this->generate_runtime_builder($manager); + } catch (\Throwable $throwable) { + $output->write($throwable->getMessage()); + } finally { return 1; } - if ($manager->isRunner() && $input->getArgument('action') == 'start') { - $output->write('Service is running. Please use restart.'); - return 1; - } - $manager->shutdown(); - if ($input->getArgument('action') == 'stop') { - $output->write('shutdown success'); - return 1; - } - return $this->generate_runtime_builder($manager); } /** * @param $manager - * @return mixed + * @return void * @throws NotFindClassException * @throws ReflectionException */ - private function generate_runtime_builder($manager): mixed + private function generate_runtime_builder($manager): void { exec(PHP_BINARY . ' ' . APP_PATH . 'kiri.php runtime:builder'); @@ -93,8 +93,6 @@ class Command extends \Symfony\Component\Console\Command\Command $this->eventProvider->on(OnWorkerStart::class, [di(WorkerDispatch::class), 'dispatch']); $manager->start(); - - return 0; } } diff --git a/http-helper/ServerProviders.php b/http-server/ServerProviders.php similarity index 87% rename from http-helper/ServerProviders.php rename to http-server/ServerProviders.php index a3cc8376..19ce79ea 100644 --- a/http-helper/ServerProviders.php +++ b/http-server/ServerProviders.php @@ -1,7 +1,7 @@ get(\Symfony\Component\Console\Application::class); - $console->add($container->get(Command::class)); + $console->add($container->get(ServerCommand::class)); } }