From b417b62a922e806d8e18528af840750e75a28ea0 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 6 Apr 2017 09:36:21 -0700 Subject: [PATCH] [WebServerBundle] added a way to dump current status host/port/address when getting the status --- .../Command/ServerStatusCommand.php | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/WebServerBundle/Command/ServerStatusCommand.php b/src/Symfony/Bundle/WebServerBundle/Command/ServerStatusCommand.php index 91ec0d2958..eff8e6be7d 100644 --- a/src/Symfony/Bundle/WebServerBundle/Command/ServerStatusCommand.php +++ b/src/Symfony/Bundle/WebServerBundle/Command/ServerStatusCommand.php @@ -35,6 +35,7 @@ class ServerStatusCommand extends ServerCommand ->setName('server:status') ->setDefinition(array( new InputOption('pidfile', null, InputOption::VALUE_REQUIRED, 'PID file'), + new InputOption('filter', null, InputOption::VALUE_REQUIRED, 'The value to display (one of port, host, or address)'), )) ->setDescription('Outputs the status of the local web server for the given address') ; @@ -47,10 +48,29 @@ class ServerStatusCommand extends ServerCommand { $io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output); $server = new WebServer(); - if ($server->isRunning($input->getOption('pidfile'))) { - $io->success(sprintf('Web server still listening on http://%s', $server->getAddress($input->getOption('pidfile')))); + if ($filter = $input->getOption('filter')) { + if ($server->isRunning($input->getOption('pidfile'))) { + list($host, $port) = explode(':', $address = $server->getAddress($input->getOption('pidfile'))); + if ('address' === $filter) { + $output->write($address); + } elseif ('host' === $filter) { + $output->write($host); + } elseif ('port' === $filter) { + $output->write($port); + } else { + throw new \InvalidArgumentException(sprintf('"%s" is not a valid filter.', $filter)); + } + } else { + return 1; + } } else { - $io->warning('No web server is listening.'); + if ($server->isRunning($input->getOption('pidfile'))) { + $io->success(sprintf('Web server still listening on http://%s', $server->getAddress($input->getOption('pidfile')))); + } else { + $io->warning('No web server is listening.'); + + return 1; + } } } }