[FrameworkBundle][Server Command] add address port number option.
This commit is contained in:
parent
222701f5e1
commit
fbe1a43990
@ -44,7 +44,8 @@ class ServerRunCommand extends ContainerAwareCommand
|
|||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->setDefinition(array(
|
->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('docroot', 'd', InputOption::VALUE_REQUIRED, 'Document root', null),
|
||||||
new InputOption('router', 'r', InputOption::VALUE_REQUIRED, 'Path to custom router script'),
|
new InputOption('router', 'r', InputOption::VALUE_REQUIRED, 'Path to custom router script'),
|
||||||
))
|
))
|
||||||
@ -101,10 +102,15 @@ EOF
|
|||||||
$output->writeln('<error>Running PHP built-in server in production environment is NOT recommended!</error>');
|
$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.');
|
$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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +137,7 @@ EOF
|
|||||||
return $process->getExitCode();
|
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
|
$router = $input->getOption('router') ?: $this
|
||||||
->getContainer()
|
->getContainer()
|
||||||
@ -154,6 +160,6 @@ EOF
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ProcessBuilder(array($binary, '-S', $input->getArgument('address'), $router));
|
return new ProcessBuilder(array($binary, '-S', $address, $router));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,8 @@ class ServerStartCommand extends ServerCommand
|
|||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->setDefinition(array(
|
->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('docroot', 'd', InputOption::VALUE_REQUIRED, 'Document root', null),
|
||||||
new InputOption('router', 'r', InputOption::VALUE_REQUIRED, 'Path to custom router script'),
|
new InputOption('router', 'r', InputOption::VALUE_REQUIRED, 'Path to custom router script'),
|
||||||
))
|
))
|
||||||
@ -101,9 +102,7 @@ EOF
|
|||||||
$address = $input->getArgument('address');
|
$address = $input->getArgument('address');
|
||||||
|
|
||||||
if (false === strpos($address, ':')) {
|
if (false === strpos($address, ':')) {
|
||||||
$output->writeln('The address has to be of the form <comment>bind-address:port</comment>.');
|
$address = $address.':'.$input->getOption('port');
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->isOtherServerProcessRunning($address)) {
|
if ($this->isOtherServerProcessRunning($address)) {
|
||||||
|
@ -14,6 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\Command;
|
|||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stops a background process running PHP's built-in web server.
|
* Stops a background process running PHP's built-in web server.
|
||||||
@ -29,7 +30,8 @@ class ServerStopCommand extends ServerCommand
|
|||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->setDefinition(array(
|
->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')
|
->setName('server:stop')
|
||||||
->setDescription('Stops PHP\'s built-in web server that was started with the server:start command')
|
->setDescription('Stops PHP\'s built-in web server that was started with the server:start command')
|
||||||
@ -53,6 +55,10 @@ EOF
|
|||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
$address = $input->getArgument('address');
|
$address = $input->getArgument('address');
|
||||||
|
if (false === strpos($address, ':')) {
|
||||||
|
$address = $address.':'.$input->getOption('port');
|
||||||
|
}
|
||||||
|
|
||||||
$lockFile = $this->getLockFile($address);
|
$lockFile = $this->getLockFile($address);
|
||||||
|
|
||||||
if (!file_exists($lockFile)) {
|
if (!file_exists($lockFile)) {
|
||||||
|
Reference in New Issue
Block a user