Skip to content

[FrameworkBundle][Server Command] add address port number option. #14383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2015
Merged
Show file tree
Hide file tree
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
16 changes: 11 additions & 5 deletions src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php
Original file line number Diff line number Diff line change
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));
}
}
Original file line number Diff line number Diff line change
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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you revert this change (i.e. moving the blank line down again)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted


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
Original file line number Diff line number Diff line change
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
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