From 7cc8475a78530aa0a2e33fb72221b6c347839727 Mon Sep 17 00:00:00 2001 From: zhaoyj Date: Wed, 10 Jun 2026 00:14:33 +0800 Subject: [PATCH] =?UTF-8?q?feature:php=20think=20run=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E.env=E6=96=87=E4=BB=B6=E9=85=8D?= =?UTF-8?q?=E7=BD=AEhost=E5=92=8Cport?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/think/console/command/RunServer.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) 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); }