Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/think/console/command/RunServer.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
Expand All @@ -8,7 +9,7 @@
// +----------------------------------------------------------------------
// | Author: Slince <taosikai@yeah.net>
// +----------------------------------------------------------------------
declare (strict_types = 1);
declare (strict_types=1);

namespace think\console\command;

Expand All @@ -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');
}
Expand All @@ -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 <http://%s:%s/>', $host, $port));
$output->writeln(sprintf('You can exit with <info>`CTRL-C`</info>'));
$output->writeln('You can exit with <info>`CTRL-C`</info>');
$output->writeln(sprintf('Document root is: %s', $root));
passthru($command);
}
Expand Down