diff --git a/src/think/console/command/RunServer.php b/src/think/console/command/RunServer.php index 92bdd3d49e..4247232031 100644 --- a/src/think/console/command/RunServer.php +++ b/src/think/console/command/RunServer.php @@ -1,4 +1,5 @@ // +---------------------------------------------------------------------- -declare (strict_types = 1); +declare (strict_types=1); namespace think\console\command; @@ -27,21 +28,21 @@ public function configure() 'H', Option::VALUE_OPTIONAL, 'The host to server the application on', - '0.0.0.0' + '0.0.0.0', ) ->addOption( 'port', 'p', Option::VALUE_OPTIONAL, 'The port to server the application on', - 8000 + 8000, ) ->addOption( 'root', 'r', Option::VALUE_OPTIONAL, 'The document root of the application', - '' + '', ) ->setDescription('PHP Built-in Server for ThinkPHP'); } @@ -50,22 +51,28 @@ public function execute(Input $input, Output $output) { $host = $input->getOption('host'); $port = $input->getOption('port'); + $envHost = \think\facade\Env::get('builtin-server.host'); + $envPort = \think\facade\Env::get('builtin-server.port'); + if (!$input->hasParameterOption(['--host', '-H']) && !empty($envHost)) { + $host = $envHost; + } + if (!$input->hasParameterOption(['--port', '-p']) && !empty($envPort)) { + $port = $envPort; + } $root = $input->getOption('root'); if (empty($root)) { $root = $this->app->getRootPath() . 'public'; } - $command = sprintf( '"%s" -S %s:%d -t %s %s', PHP_BINARY, $host, $port, escapeshellarg($root), - escapeshellarg($root . DIRECTORY_SEPARATOR . 'router.php') + escapeshellarg($root . DIRECTORY_SEPARATOR . 'router.php'), ); - $output->writeln(sprintf('ThinkPHP Development server is started On ', $host, $port)); - $output->writeln(sprintf('You can exit with `CTRL-C`')); + $output->writeln('You can exit with `CTRL-C`'); $output->writeln(sprintf('Document root is: %s', $root)); passthru($command); }