|
17 | 17 | use \InitPHP\Framework\Console\Command; |
18 | 18 | use Symfony\Component\Console\Input\InputArgument; |
19 | 19 | use Symfony\Component\Console\Input\InputInterface; |
| 20 | +use Symfony\Component\Console\Input\InputOption; |
20 | 21 | use Symfony\Component\Console\Output\OutputInterface; |
21 | 22 |
|
22 | 23 | class ServeCommand extends Command |
23 | 24 | { |
24 | 25 |
|
25 | 26 | protected static $defaultName = 'serve'; |
26 | 27 |
|
27 | | - protected function execute(InputInterface $input, OutputInterface $output): int |
| 28 | + protected function execute(InputInterface $input, OutputInterface $output) |
28 | 29 | { |
29 | | - $host = $input->hasArgument("host") ? $input->getArgument("host") : "127.0.0.1"; |
30 | | - $port = $input->hasArgument("port") ? $input->getArgument("port") : 8000; |
31 | | - !is_int($port) && $port = 8000; |
| 30 | + $host = $input->getOption("host"); |
| 31 | + $port = intval($input->getOption("port")); |
32 | 32 |
|
33 | 33 | $shell = "php -S " . $host . ":" . $port . " -t \"" . PUBLIC_DIR . "\""; |
34 | 34 | exec($shell); |
35 | 35 |
|
36 | 36 | return Command::SUCCESS; |
37 | 37 | } |
38 | 38 |
|
39 | | - protected function configure(): void |
| 39 | + protected function configure() |
40 | 40 | { |
41 | 41 | $this->setDescription('It runs a PHP Web server.') |
42 | | - ->addArgument('host', InputArgument::OPTIONAL, 'The host name or IP', '127.0.0.1') |
43 | | - ->addArgument('port', InputArgument::OPTIONAL, 'The port', '8000'); |
| 42 | + ->addOption('host', 'host', InputOption::VALUE_OPTIONAL, 'The host name or IP', '127.0.0.1') |
| 43 | + ->addOption('port', 'p', InputOption::VALUE_OPTIONAL, 'The port', '8000'); |
44 | 44 | } |
45 | 45 |
|
46 | 46 | } |
0 commit comments