Skip to content

Commit

Permalink
Fix server
Browse files Browse the repository at this point in the history
  • Loading branch information
asika32764 committed Sep 21, 2023
1 parent ef23569 commit 7226ab3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/Core/CliServer/Command/ServerCommandTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 6 additions & 3 deletions src/Core/CliServer/Command/ServerStartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'),
]
);
Expand All @@ -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')),
Expand Down Expand Up @@ -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);
}
Expand Down
8 changes: 8 additions & 0 deletions src/Core/CliServer/PhpNative/PhpNativeEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class PhpNativeEngine implements CliServerEngineInterface
use OptionsResolverTrait;

public function __construct(
protected string $name,
protected ConsoleApplication $app,
protected ConsoleOutputInterface $output,
array $options = []
Expand All @@ -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
Expand Down Expand Up @@ -123,4 +126,9 @@ public function isRunning(): bool
{
return false;
}

public function getName(): string
{
return $this->name;
}
}

0 comments on commit 7226ab3

Please sign in to comment.