From 7226ab327518d8f50fdccdc5994e9fe79ead9eaf Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Thu, 21 Sep 2023 16:48:40 +0800 Subject: [PATCH] Fix server --- src/Core/CliServer/Command/ServerCommandTrait.php | 7 +++++++ src/Core/CliServer/Command/ServerStartCommand.php | 9 ++++++--- src/Core/CliServer/PhpNative/PhpNativeEngine.php | 8 ++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Core/CliServer/Command/ServerCommandTrait.php b/src/Core/CliServer/Command/ServerCommandTrait.php index a0ea46b0..fdb39b31 100644 --- a/src/Core/CliServer/Command/ServerCommandTrait.php +++ b/src/Core/CliServer/Command/ServerCommandTrait.php @@ -66,6 +66,13 @@ protected function getMainFile(IOInterface $io, string $engine, string $name): s $main = $servers[$name] ?? ''; } + return $main; + } + + protected function mustGetMainFile(IOInterface $io, string $engine, string $name): string + { + $main = $this->getMainFile($io, $engine, $name); + if (!$main || !is_file($main)) { throw new \InvalidArgumentException( sprintf( diff --git a/src/Core/CliServer/Command/ServerStartCommand.php b/src/Core/CliServer/Command/ServerStartCommand.php index b42fff6c..9ad41b88 100644 --- a/src/Core/CliServer/Command/ServerStartCommand.php +++ b/src/Core/CliServer/Command/ServerStartCommand.php @@ -20,6 +20,7 @@ use Windwalker\Console\CommandWrapper; use Windwalker\Console\IOInterface; use Windwalker\Core\CliServer\CliServerFactory; +use Windwalker\Core\CliServer\Contracts\ServerProcessManageInterface; use Windwalker\Core\Console\ConsoleApplication; use Windwalker\DI\Attributes\Autowire; use Windwalker\Utilities\TypeCast; @@ -192,7 +193,7 @@ protected function runPhpServer(IOInterface $io, string $domain, int $port): int $domain, $port, [ - 'main' => $this->getMainFile($name, 'php', $name), + 'main' => $this->getMainFile($io, 'php', $name), 'docroot' => $io->getOption('docroot'), ] ); @@ -208,7 +209,7 @@ protected function runSwooleServer(IOInterface $io, ?string $domain, int $port): $port, [ 'process_name' => $this->app->getAppName(), - 'main' => $this->getMainFile($io, 'swoole', $name), + 'main' => $this->mustGetMainFile($io, 'swoole', $name), 'app' => $io->getOption('app'), 'workers' => TypeCast::safeInteger($io->getOption('workers')), 'task_workers' => TypeCast::safeInteger($io->getOption('task-workers')), @@ -256,7 +257,9 @@ public function handleSignal(int $signal): void $engine = $this->createEngine($engineName, $name, $this->io); - $engine->stopServer(); + if ($engine instanceof ServerProcessManageInterface) { + $engine->stopServer(); + } exit(0); } diff --git a/src/Core/CliServer/PhpNative/PhpNativeEngine.php b/src/Core/CliServer/PhpNative/PhpNativeEngine.php index b4169efc..d77809bd 100644 --- a/src/Core/CliServer/PhpNative/PhpNativeEngine.php +++ b/src/Core/CliServer/PhpNative/PhpNativeEngine.php @@ -33,6 +33,7 @@ class PhpNativeEngine implements CliServerEngineInterface use OptionsResolverTrait; public function __construct( + protected string $name, protected ConsoleApplication $app, protected ConsoleOutputInterface $output, array $options = [] @@ -47,6 +48,8 @@ protected function configureOptions(OptionsResolver $resolver): void $resolver->define('docroot') ->allowedTypes('string', 'null'); + + $resolver->setDefined(['state_file']); } public static function isSupported(): bool @@ -123,4 +126,9 @@ public function isRunning(): bool { return false; } + + public function getName(): string + { + return $this->name; + } }