This commit is contained in:
2021-09-02 13:59:00 +08:00
parent 648e698d9e
commit c5b370dabc
6 changed files with 31 additions and 35 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ use Http\Context\HttpHeaders;
use Http\Context\HttpParams; use Http\Context\HttpParams;
use Http\Context\Response; use Http\Context\Response;
use Http\Route\Router; use Http\Route\Router;
use Http\Server; use Server\Server;
use Http\Shutdown; use Http\Shutdown;
use JetBrains\PhpStorm\Pure; use JetBrains\PhpStorm\Pure;
use Kafka\KafkaProvider; use Kafka\KafkaProvider;
+1 -1
View File
@@ -11,7 +11,7 @@ use Http\Client\Curl;
use Http\Context\Response; use Http\Context\Response;
use Http\HttpFilter; use Http\HttpFilter;
use Http\Route\Router; use Http\Route\Router;
use Http\Server; use Server\Server;
use Http\Shutdown; use Http\Shutdown;
use Kiri\Crontab\Producer; use Kiri\Crontab\Producer;
use Kiri\Async; use Kiri\Async;
+3 -3
View File
@@ -15,9 +15,9 @@ use Console\Console;
use Console\ConsoleProviders; use Console\ConsoleProviders;
use Database\DatabasesProviders; use Database\DatabasesProviders;
use Exception; use Exception;
use Http\Command; use Server\ServerCommand;
use Http\Context\Response; use Http\Context\Response;
use Http\ServerProviders; use Server\ServerProviders;
use Kiri\Abstracts\BaseApplication; use Kiri\Abstracts\BaseApplication;
use Kiri\Abstracts\Config; use Kiri\Abstracts\Config;
use Kiri\Abstracts\Kernel; use Kiri\Abstracts\Kernel;
@@ -240,7 +240,7 @@ class Application extends BaseApplication
*/ */
private function enableFileChange($class): void private function enableFileChange($class): void
{ {
if (!($class instanceof Command)) { if (!($class instanceof ServerCommand)) {
scan_directory(directory('app'), 'App'); scan_directory(directory('app'), 'App');
} }
} }
@@ -1,7 +1,7 @@
<?php <?php
namespace Http; namespace Server;
use Annotation\Inject; use Annotation\Inject;
use Exception; use Exception;
@@ -12,9 +12,7 @@ use Kiri\Error\LoggerProcess;
use Kiri\Events\EventDispatch; use Kiri\Events\EventDispatch;
use Kiri\Exception\ConfigException; use Kiri\Exception\ConfigException;
use Kiri\Rpc\Service; use Kiri\Rpc\Service;
use ReflectionException;
use Server\Events\OnShutdown; use Server\Events\OnShutdown;
use Server\ServerManager;
use Swoole\Runtime; use Swoole\Runtime;
@@ -1,13 +1,12 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Http; namespace Server;
use Annotation\Inject; use Annotation\Inject;
use Exception; use Exception;
use Kiri\Events\EventProvider; use Kiri\Events\EventProvider;
use Kiri\Exception\ConfigException;
use Kiri\Exception\NotFindClassException; use Kiri\Exception\NotFindClassException;
use Kiri\Kiri; use Kiri\Kiri;
use ReflectionException; use ReflectionException;
@@ -15,6 +14,7 @@ use Server\Events\OnBeforeWorkerStart;
use Server\Events\OnWorkerStart; use Server\Events\OnWorkerStart;
use Server\Worker\OnServerWorker; use Server\Worker\OnServerWorker;
use Server\Worker\OnWorkerStart as WorkerDispatch; use Server\Worker\OnWorkerStart as WorkerDispatch;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@@ -23,7 +23,7 @@ use Symfony\Component\Console\Output\OutputInterface;
* Class Command * Class Command
* @package Http * @package Http
*/ */
class Command extends \Symfony\Component\Console\Command\Command class ServerCommand extends Command
{ {
@@ -52,40 +52,40 @@ class Command extends \Symfony\Component\Console\Command\Command
/** /**
* @param InputInterface $input * @param InputInterface $input
* @param OutputInterface $output * @param OutputInterface $output
* @return string * @return int
* @throws ConfigException
* @throws NotFindClassException
* @throws ReflectionException
* @throws Exception * @throws Exception
*/ */
public function execute(InputInterface $input, OutputInterface $output): int public function execute(InputInterface $input, OutputInterface $output): int
{ {
try {
$manager = Kiri::app()->getServer(); $manager = Kiri::app()->getServer();
$manager->setDaemon($input->getArgument('daemon')); $manager->setDaemon($input->getArgument('daemon'));
if (!in_array($input->getArgument('action'), self::ACTIONS)) { if (!in_array($input->getArgument('action'), self::ACTIONS)) {
$output->write('I don\'t know what I want to do.'); throw new Exception('I don\'t know what I want to do.');
return 1;
} }
if ($manager->isRunner() && $input->getArgument('action') == 'start') { if ($manager->isRunner() && $input->getArgument('action') == 'start') {
$output->write('Service is running. Please use restart.'); throw new Exception('Service is running. Please use restart.');
return 1;
} }
$manager->shutdown(); $manager->shutdown();
if ($input->getArgument('action') == 'stop') { if ($input->getArgument('action') == 'stop') {
$output->write('shutdown success'); throw new Exception('shutdown success');
}
$this->generate_runtime_builder($manager);
} catch (\Throwable $throwable) {
$output->write($throwable->getMessage());
} finally {
return 1; return 1;
} }
return $this->generate_runtime_builder($manager);
} }
/** /**
* @param $manager * @param $manager
* @return mixed * @return void
* @throws NotFindClassException * @throws NotFindClassException
* @throws ReflectionException * @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'); 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']); $this->eventProvider->on(OnWorkerStart::class, [di(WorkerDispatch::class), 'dispatch']);
$manager->start(); $manager->start();
return 0;
} }
} }
@@ -1,7 +1,7 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Http; namespace Server;
use Exception; use Exception;
@@ -28,7 +28,7 @@ class ServerProviders extends Providers
$container = Kiri::getDi(); $container = Kiri::getDi();
$console = $container->get(\Symfony\Component\Console\Application::class); $console = $container->get(\Symfony\Component\Console\Application::class);
$console->add($container->get(Command::class)); $console->add($container->get(ServerCommand::class));
} }
} }