8000 feature #14383 [FrameworkBundle][Server Command] add address port num… · symfony/symfony@6bab76d · GitHub
[go: up one dir, main page]

Skip to content

Commit 6bab76d

Browse files
committed
feature #14383 [FrameworkBundle][Server Command] add address port number option. (aitboudad)
This PR was merged into the 2.8 branch. Discussion ---------- [FrameworkBundle][Server Command] add address port number option. | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | ~ | License | MIT | Doc PR | ~ This allow running server without repeating `127.0.0.1` each time, in the most of case we only change the port number. * Before ``` app/console server:start 127.0.0.1:8080 ``` * After ``` app/console server:start -p 8080 ``` Commits ------- fbe1a43 [FrameworkBundle][Server Command] add address port number option.
2 parents 222701f + fbe1a43 commit 6bab76d

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
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: 3 additions & 4 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
))
@@ -101,9 +102,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
101102
$address = $input->getArgument('address');
102103

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)
0