Skip to content

Commit

Permalink
[FrameworkBundle][Server Command] add address port number option.
Browse files Browse the repository at this point in the history
  • Loading branch information
aitboudad committed Apr 17, 2015
1 parent 222701f commit fbe1a43
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
16 changes: 11 additions & 5 deletions src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php
Expand Up @@ -44,7 +44,8 @@ protected function configure()
{
$this
->setDefinition(array(
new InputArgument('address', InputArgument::OPTIONAL, 'Address:port', '127.0.0.1:8000'),
new InputArgument('address', InputArgument::OPTIONAL, 'Address:port', '127.0.0.1'),
new InputOption('port', 'p', InputOption::VALUE_REQUIRED, 'Address port number', '8000'),
new InputOption('docroot', 'd', InputOption::VALUE_REQUIRED, 'Document root', null),
new InputOption('router', 'r', InputOption::VALUE_REQUIRED, 'Path to custom router script'),
))
Expand Down Expand Up @@ -101,10 +102,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln('<error>Running PHP built-in server in production environment is NOT recommended!</error>');
}

$output->writeln(sprintf("Server running on <info>http://%s</info>\n", $input->getArgument('address')));
$address = $input->getArgument('address');
if (false === strpos($address, ':')) {
$address = $address.':'.$input->getOption('port');
}

$output->writeln(sprintf("Server running on <info>http://%s</info>\n", $address));
$output->writeln('Quit the server with CONTROL-C.');

if (null === $builder = $this->createPhpProcessBuilder($input, $output, $env)) {
if (null === $builder = $this->createPhpProcessBuilder($input, $output, $env, $address)) {
return 1;
}

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

private function createPhpProcessBuilder(InputInterface $input, OutputInterface $output, $env)
private function createPhpProcessBuilder(InputInterface $input, OutputInterface $output, $env, $address)
{
$router = $input->getOption('router') ?: $this
->getContainer()
Expand All @@ -154,6 +160,6 @@ private function createPhpProcessBuilder(InputInterface $input, OutputInterface
return;
}

return new ProcessBuilder(array($binary, '-S', $input->getArgument('address'), $router));
return new ProcessBuilder(array($binary, '-S', $address, $router));
}
}
Expand Up @@ -33,7 +33,8 @@ protected function configure()
{
$this
->setDefinition(array(
new InputArgument('address', InputArgument::OPTIONAL, 'Address:port', '127.0.0.1:8000'),
new InputArgument('address', InputArgument::OPTIONAL, 'Address:port', '127.0.0.1'),
new InputOption('port', 'p', InputOption::VALUE_REQUIRED, 'Address port number', '8000'),
new InputOption('docroot', 'd', InputOption::VALUE_REQUIRED, 'Document root', null),
new InputOption('router', 'r', InputOption::VALUE_REQUIRED, 'Path to custom router script'),
))
Expand Down Expand Up @@ -101,9 +102,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$address = $input->getArgument('address');

if (false === strpos($address, ':')) {
$output->writeln('The address has to be of the form <comment>bind-address:port</comment>.');

return 1;
$address = $address.':'.$input->getOption('port');
}

if ($this->isOtherServerProcessRunning($address)) {
Expand Down
Expand Up @@ -14,6 +14,7 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;

/**
* Stops a background process running PHP's built-in web server.
Expand All @@ -29,7 +30,8 @@ protected function configure()
{
$this
->setDefinition(array(
new InputArgument('address', InputArgument::OPTIONAL, 'Address:port', '127.0.0.1:8000'),
new InputArgument('address', InputArgument::OPTIONAL, 'Address:port', '127.0.0.1'),
new InputOption('port', 'p', InputOption::VALUE_REQUIRED, 'Address port number', '8000'),
))
->setName('server:stop')
->setDescription('Stops PHP\'s built-in web server that was started with the server:start command')
Expand All @@ -53,6 +55,10 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$address = $input->getArgument('address');
if (false === strpos($address, ':')) {
$address = $address.':'.$input->getOption('port');
}

$lockFile = $this->getLockFile($address);

if (!file_exists($lockFile)) {
Expand Down

0 comments on commit fbe1a43

Please sign in to comment.