From fbe1a43990fc85adff8d41c91fd0730a52b1d472 Mon Sep 17 00:00:00 2001 From: Abdellatif Ait boudad Date: Thu, 16 Apr 2015 23:28:34 +0100 Subject: [PATCH] [FrameworkBundle][Server Command] add address port number option. --- .../FrameworkBundle/Command/ServerRunCommand.php | 16 +++++++++++----- .../Command/ServerStartCommand.php | 7 +++---- .../Command/ServerStopCommand.php | 8 +++++++- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php index 01a1e4da7ffd4..919713cd05937 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php @@ -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'), )) @@ -101,10 +102,15 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln('Running PHP built-in server in production environment is NOT recommended!'); } - $output->writeln(sprintf("Server running on http://%s\n", $input->getArgument('address'))); + $address = $input->getArgument('address'); + if (false === strpos($address, ':')) { + $address = $address.':'.$input->getOption('port'); + } + + $output->writeln(sprintf("Server running on http://%s\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; } @@ -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() @@ -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)); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php index 9110bb1b4337d..c919dfa00c10a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php @@ -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'), )) @@ -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 bind-address:port.'); - - return 1; + $address = $address.':'.$input->getOption('port'); } if ($this->isOtherServerProcessRunning($address)) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ServerStopCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ServerStopCommand.php index 9b0656c220b66..c40952059a294 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ServerStopCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ServerStopCommand.php @@ -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. @@ -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') @@ -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)) { 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