Skip to content

Commit 83dbaae

Browse files
committed
[FrameworkBundle][Server Command] add address port number option.
1 parent 222701f commit 83dbaae

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ protected function configure()
4444
{
4545
$this
4646
->setDefinition(array(
47-
new InputArgument('address', InputArgument::OPTIONAL, 'Address:port', '127.0.0.1:8000'),
47+
new InputArgument('address', InputArgument::OPTIONAL, 'Address:port', '127.0.0.1'),
48+
new InputOption('port', 'p', InputOption::VALUE_REQUIRED, 'Address port number', '8000'),
4849
new InputOption('docroot', 'd', InputOption::VALUE_REQUIRED, 'Document root', null),
4950
new InputOption('router', 'r', InputOption::VALUE_REQUIRED, 'Path to custom router script'),
5051
))
@@ -101,10 +102,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
101102
$output->writeln('<error>Running PHP built-in server in production environment is NOT recommended!</error>');
102103
}
103104

104-
$output->writeln(sprintf("Server running on <info>http://%s</info>\n", $input->getArgument('address')));
105+
$address = $input->getArgument('address');
106+
if (false === strpos($address, ':')) {
107+
$address = $address.':'.$input->getOption('port');
108+
}
109+
110+
$output->writeln(sprintf("Server running on <info>http://%s</info>\n", $address));
105111
$output->writeln('Quit the server with CONTROL-C.');
106112

107-
if (null === $builder = $this->createPhpProcessBuilder($input, $output, $env)) {
113+
if (null === $builder = $this->createPhpProcessBuilder($input, $output, $env, $address)) {
108114
return 1;
109115
}
110116

@@ -131,7 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
131137
return $process->getExitCode();
132138
}
133139

134-
private function createPhpProcessBuilder(InputInterface $input, OutputInterface $output, $env)
140+
private function createPhpProcessBuilder(InputInterface $input, OutputInterface $output, $env, $address)
135141
{
136142
$router = $input->getOption('router') ?: $this
137143
->getContainer()
@@ -154,6 +160,6 @@ private function createPhpProcessBuilder(InputInterface $input, OutputInterface
154160
return;
155161
}
156162

157-
return new ProcessBuilder(array($binary, '-S', $input->getArgument('address'), $router));
163+
return new ProcessBuilder(array($binary, '-S', $address, $router));
158164
}
159165
}

src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ protected function configure()
3333
{
3434
$this
3535
->setDefinition(array(
36-
new InputArgument('address', InputArgument::OPTIONAL, 'Address:port', '127.0.0.1:8000'),
36+
new InputArgument('address', InputArgument::OPTIONAL, 'Address:port', '127.0.0.1'),
37+
new InputOption('port', 'p', InputOption::VALUE_REQUIRED, 'Address port number', '8000'),
3738
new InputOption('docroot', 'd', InputOption::VALUE_REQUIRED, 'Document root', null),
3839
new InputOption('router', 'r', InputOption::VALUE_REQUIRED, 'Path to custom router script'),
3940
))
@@ -98,12 +99,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
9899
}
99100

100101
$env = $this->getContainer()->getParameter('kernel.environment');
101-
$address = $input->getArgument('address');
102102

103+
$address = $input->getArgument('address');
103104
if (false === strpos($address, ':')) {
104-
$output->writeln('The address has to be of the form <comment>bind-address:port</comment>.');
105-
106-
return 1;
105+
$address = $address.':'.$input->getOption('port');
107106
}
108107

109108
if ($this->isOtherServerProcessRunning($address)) {

src/Symfony/Bundle/FrameworkBundle/Command/ServerStopCommand.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Console\Input\InputArgument;
1515
use Symfony\Component\Console\Input\InputInterface;
1616
use Symfony\Component\Console\Output\OutputInterface;
17+
use Symfony\Component\Console\Input\InputOption;
1718

1819
/**
1920
* Stops a background process running PHP's built-in web server.
@@ -29,7 +30,8 @@ protected function configure()
2930
{
3031
$this
3132
->setDefinition(array(
32-
new InputArgument('address', InputArgument::OPTIONAL, 'Address:port', '127.0.0.1:8000'),
33+
new InputArgument('address', InputArgument::OPTIONAL, 'Address:port', '127.0.0.1'),
34+
new InputOption('port', 'p', InputOption::VALUE_REQUIRED, 'Address port number', '8000'),
3335
))
3436
->setName('server:stop')
3537
->setDescription('Stops PHP\'s built-in web server that was started with the server:start command')
@@ -53,6 +55,10 @@ protected function configure()
5355
protected function execute(InputInterface $input, OutputInterface $output)
5456
{
5557
$address = $input->getArgument('address');
58+
if (false === strpos($address, ':')) {
59+
$address = $address.':'.$input->getOption('port');
60+
}
61+
5662
$lockFile = $this->getLockFile($address);
5763

5864
if (!file_exists($lockFile)) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy