-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Updated the styles of the server commands #15972
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use Symfony\Component\Process\PhpExecutableFinder; | ||
use Symfony\Component\Process\ProcessBuilder; | ||
|
||
|
@@ -84,14 +85,16 @@ protected function configure() | |
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$stdout = $output; | ||
$output = new SymfonyStyle($input, $output); | ||
$documentRoot = $input->getOption('docroot'); | ||
|
||
if (null === $documentRoot) { | ||
$documentRoot = $this->getContainer()->getParameter('kernel.root_dir').'/../web'; | ||
} | ||
|
||
if (!is_dir($documentRoot)) { | ||
$output->writeln(sprintf('<error>The given document root directory "%s" does not exist</error>', $documentRoot)); | ||
$output->error(sprintf('The given document root directory "%s" does not exist', $documentRoot)); | ||
|
||
return 1; | ||
} | ||
|
@@ -104,17 +107,17 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
} | ||
|
||
if ($this->isOtherServerProcessRunning($address)) { | ||
$output->writeln(sprintf('<error>A process is already listening on http://%s.</error>', $address)); | ||
$output->error(sprintf('A process is already listening on http://%s.', $address)); | ||
|
||
return 1; | ||
} | ||
|
||
if ('prod' === $env) { | ||
$output->writeln('<error>Running PHP built-in server in production environment is NOT recommended!</error>'); | ||
$output->error('Running PHP built-in server in production environment is NOT recommended!'); | ||
} | ||
|
||
$output->writeln(sprintf("Server running on <info>http://%s</info>\n", $address)); | ||
$output->writeln('Quit the server with CONTROL-C.'); | ||
$output->success(sprintf('Server running on http://%s', $address)); | ||
$output->comment('Quit the server with CONTROL-C.'); | ||
|
||
if (null === $builder = $this->createPhpProcessBuilder($output, $address, $input->getOption('router'), $env)) { | ||
return 1; | ||
|
@@ -124,26 +127,28 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
$builder->setTimeout(null); | ||
$process = $builder->getProcess(); | ||
|
||
if (OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) { | ||
if (OutputInterface::VERBOSITY_VERBOSE > $stdout->getVerbosity()) { | ||
$process->disableOutput(); | ||
} | ||
|
||
$this | ||
->getHelper('process') | ||
->run($output, $process, null, null, OutputInterface::VERBOSITY_VERBOSE); | ||
->run($stdout, $process, null, null, OutputInterface::VERBOSITY_VERBOSE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm since the OutputStyle has no idea of ConsoleOutput, which knows the stderr, the process helper actually really needs the original ConsoleOutput. Otherwise the process data would not be written to stderr but to stdout. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created #15986 as a general problem |
||
|
||
if (!$process->isSuccessful()) { | ||
$output->writeln('<error>Built-in server terminated unexpectedly</error>'); | ||
$errorMessages = array('Built-in server terminated unexpectedly.'); | ||
|
||
if ($process->isOutputDisabled()) { | ||
$output->writeln('<error>Run the command again with -v option for more details</error>'); | ||
$errorMessages[] = 'Run the command again with -v option for more details.'; | ||
} | ||
|
||
$output->error($errorMessages); | ||
} | ||
|
||
return $process->getExitCode(); | ||
} | ||
|
||
private function createPhpProcessBuilder(OutputInterface $output, $address, $router, $env) | ||
private function createPhpProcessBuilder(SymfonyStyle $output, $address, $router, $env) | ||
{ | ||
$router = $router ?: $this | ||
->getContainer() | ||
|
@@ -152,7 +157,7 @@ private function createPhpProcessBuilder(OutputInterface $output, $address, $rou | |
; | ||
|
||
if (!file_exists($router)) { | ||
$output->writeln(sprintf('<error>The given router script "%s" does not exist</error>', $router)); | ||
$output->error(sprintf('The given router script "%s" does not exist.', $router)); | ||
|
||
return; | ||
} | ||
|
@@ -161,7 +166,7 @@ private function createPhpProcessBuilder(OutputInterface $output, $address, $rou | |
$finder = new PhpExecutableFinder(); | ||
|
||
if (false === $binary = $finder->find()) { | ||
$output->writeln('<error>Unable to find PHP binary to run server</error>'); | ||
$output->error('Unable to find PHP binary to run server.'); | ||
|
||
return; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not needed. SymfonyStyle also implements OutputInterface. So it can be used just as $stdout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm, see below comment