Skip to content

Commit

Permalink
feature #22316 [WebServerBundle] added a way to dump current status h…
Browse files Browse the repository at this point in the history
…ost/port/address when getting the status (fabpot)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[WebServerBundle] added a way to dump current status host/port/address when getting the status

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Now that the web server can run on an automatically chosen port, it's more complex to integrate it into tests (I want to run some functional tests locally).

The `server:status` command gives this information, but not in a machine-readable way.

I propose to add a `--filter` flag to fix that:

`./bin/console server:status --filter=address`

Commits
-------

b417b62 [WebServerBundle] added a way to dump current status host/port/address when getting the status
  • Loading branch information
fabpot committed Apr 6, 2017
2 parents 3458edf + b417b62 commit abb8d2b
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/Symfony/Bundle/WebServerBundle/Command/ServerStatusCommand.php
Expand Up @@ -35,6 +35,7 @@ protected function configure()
->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')
;
Expand All @@ -47,10 +48,29 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$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;
}
}
}
}

0 comments on commit abb8d2b

Please sign in to comment.