From 1ee48bfd60021b41b63c19ad1b5be148888dee85 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Sun, 20 Nov 2016 14:10:42 +0100 Subject: [PATCH] [FrameworkBundle] Make use of stderr for non reliable output --- src/Symfony/Bridge/Twig/Command/DebugCommand.php | 4 +--- src/Symfony/Bridge/Twig/Command/LintCommand.php | 5 ++--- .../FrameworkBundle/Command/ConfigDebugCommand.php | 10 ++++++---- .../Command/ConfigDumpReferenceCommand.php | 8 +++++--- .../Command/ContainerDebugCommand.php | 13 ++++++++----- .../Command/EventDispatcherDebugCommand.php | 4 +++- .../WebServerBundle/Command/ServerRunCommand.php | 2 +- .../WebServerBundle/Command/ServerStartCommand.php | 5 +++-- .../WebServerBundle/Command/ServerStatusCommand.php | 3 ++- .../WebServerBundle/Command/ServerStopCommand.php | 3 ++- 10 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Command/DebugCommand.php b/src/Symfony/Bridge/Twig/Command/DebugCommand.php index 44e23902e0..061cd82162 100644 --- a/src/Symfony/Bridge/Twig/Command/DebugCommand.php +++ b/src/Symfony/Bridge/Twig/Command/DebugCommand.php @@ -87,9 +87,7 @@ EOF $twig = $this->getTwigEnvironment(); if (null === $twig) { - $io->error('The Twig environment needs to be set.'); - - return 1; + throw new \RuntimeException('The Twig environment needs to be set.'); } $types = array('functions', 'filters', 'tests', 'globals'); diff --git a/src/Symfony/Bridge/Twig/Command/LintCommand.php b/src/Symfony/Bridge/Twig/Command/LintCommand.php index ebbfde12c2..52102c26ff 100644 --- a/src/Symfony/Bridge/Twig/Command/LintCommand.php +++ b/src/Symfony/Bridge/Twig/Command/LintCommand.php @@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Finder\Finder; @@ -88,9 +89,7 @@ EOF $io = new SymfonyStyle($input, $output); if (null === $twig = $this->getTwigEnvironment()) { - $io->error('The Twig environment needs to be set.'); - - return 1; + throw new \RuntimeException('The Twig environment needs to be set.'); } $filenames = $input->getArgument('filename'); diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php index 921dba0dde..17ddeebf54 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php @@ -15,6 +15,7 @@ use Symfony\Component\Config\Definition\Processor; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Exception\LogicException; use Symfony\Component\Yaml\Yaml; @@ -62,11 +63,12 @@ EOF protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); + $errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io; if (null === $name = $input->getArgument('name')) { - $this->listBundles($io); - $io->comment('Provide the name of a bundle as the first argument of this command to dump its configuration. (e.g. debug:config FrameworkBundle)'); - $io->comment('For dumping a specific option, add its path as the second argument of this command. (e.g. debug:config FrameworkBundle serializer to dump the framework.serializer configuration)'); + $this->listBundles($errorIo); + $errorIo->comment('Provide the name of a bundle as the first argument of this command to dump its configuration. (e.g. debug:config FrameworkBundle)'); + $errorIo->comment('For dumping a specific option, add its path as the second argument of this command. (e.g. debug:config FrameworkBundle serializer to dump the framework.serializer configuration)'); return; } @@ -98,7 +100,7 @@ EOF try { $config = $this->getConfigForPath($config, $path, $extensionAlias); } catch (LogicException $e) { - $io->error($e->getMessage()); + $errorIo->error($e->getMessage()); return; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php index 574b496c72..4666d7bd12 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php @@ -17,6 +17,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; /** @@ -55,7 +56,7 @@ this is either yaml or xml. When the option is not provided, yaml is used. php %command.full_name% FrameworkBundle --format=xml - + For dumping a specific option, add its path as second argument (only available for the yaml format): php %command.full_name% framework profiler.matcher @@ -75,8 +76,9 @@ EOF $io = new SymfonyStyle($input, $output); if (null === $name = $input->getArgument('name')) { - $this->listBundles($io); - $io->comment(array( + $errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io; + $this->listBundles($errorIo); + $errorIo->comment(array( 'Provide the name of a bundle as the first argument of this command to dump its default configuration. (e.g. config:dump-reference FrameworkBundle)', 'For dumping a specific option, add its path as the second argument of this command. (e.g. config:dump-reference FrameworkBundle profiler.matcher to dump the framework.profiler.matcher configuration)', )); diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php index 47f08de6bc..1a2607d4b2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php @@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -94,6 +95,8 @@ EOF protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); + $errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io; + $this->validateInput($input); $object = $this->getContainerBuilder(); @@ -111,7 +114,7 @@ EOF } elseif ($tag = $input->getOption('tag')) { $options = array('tag' => $tag, 'show_private' => $input->getOption('show-private')); } elseif ($name = $input->getArgument('name')) { - $name = $this->findProperServiceName($input, $io, $object, $name); + $name = $this->findProperServiceName($input, $errorIo, $object, $name); $options = array('id' => $name); } else { $options = array('show_private' => $input->getOption('show-private')); @@ -122,15 +125,15 @@ EOF $options['show_arguments'] = $input->getOption('show-arguments'); $options['raw_text'] = $input->getOption('raw'); $options['output'] = $io; - $helper->describe($output, $object, $options); + $helper->describe($io, $object, $options); if (!$input->getArgument('name') && !$input->getOption('tag') && !$input->getOption('parameter') && $input->isInteractive()) { if ($input->getOption('tags')) { - $io->comment('To search for a specific tag, re-run this command with a search term. (e.g. debug:container --tag=form.type)'); + $errorIo->comment('To search for a specific tag, re-run this command with a search term. (e.g. debug:container --tag=form.type)'); } elseif ($input->getOption('parameters')) { - $io->comment('To search for a specific parameter, re-run this command with a search term. (e.g. debug:container --parameter=kernel.debug)'); + $errorIo->comment('To search for a specific parameter, re-run this command with a search term. (e.g. debug:container --parameter=kernel.debug)'); } else { - $io->comment('To search for a specific service, re-run this command with a search term. (e.g. debug:container log)'); + $errorIo->comment('To search for a specific service, re-run this command with a search term. (e.g. debug:container log)'); } } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/EventDispatcherDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/EventDispatcherDebugCommand.php index 2eb310ddf1..1b40c53a6c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/EventDispatcherDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/EventDispatcherDebugCommand.php @@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -65,7 +66,8 @@ EOF $options = array(); if ($event = $input->getArgument('event')) { if (!$dispatcher->hasListeners($event)) { - $io->warning(sprintf('The event "%s" does not have any registered listeners.', $event)); + $errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io; + $errorIo->warning(sprintf('The event "%s" does not have any registered listeners.', $event)); return; } diff --git a/src/Symfony/Bundle/WebServerBundle/Command/ServerRunCommand.php b/src/Symfony/Bundle/WebServerBundle/Command/ServerRunCommand.php index 4259e00713..2dd8cacaad 100644 --- a/src/Symfony/Bundle/WebServerBundle/Command/ServerRunCommand.php +++ b/src/Symfony/Bundle/WebServerBundle/Command/ServerRunCommand.php @@ -79,7 +79,7 @@ EOF */ protected function execute(InputInterface $input, OutputInterface $output) { - $io = new SymfonyStyle($input, $output); + $io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output); if (null === $documentRoot = $input->getOption('docroot')) { if (!$this->documentRoot) { diff --git a/src/Symfony/Bundle/WebServerBundle/Command/ServerStartCommand.php b/src/Symfony/Bundle/WebServerBundle/Command/ServerStartCommand.php index a490802472..c0888e944e 100644 --- a/src/Symfony/Bundle/WebServerBundle/Command/ServerStartCommand.php +++ b/src/Symfony/Bundle/WebServerBundle/Command/ServerStartCommand.php @@ -17,6 +17,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; /** @@ -79,7 +80,7 @@ EOF */ protected function execute(InputInterface $input, OutputInterface $output) { - $io = new SymfonyStyle($input, $cliOutput = $output); + $io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output); if (!extension_loaded('pcntl')) { $io->error(array( @@ -88,7 +89,7 @@ EOF )); if ($io->ask('Do you want to execute server:run immediately? [yN] ', false)) { - return $this->getApplication()->find('server:run')->run($input, $cliOutput); + return $this->getApplication()->find('server:run')->run($input, $output); } return 1; diff --git a/src/Symfony/Bundle/WebServerBundle/Command/ServerStatusCommand.php b/src/Symfony/Bundle/WebServerBundle/Command/ServerStatusCommand.php index c77f2f755f..91ec0d2958 100644 --- a/src/Symfony/Bundle/WebServerBundle/Command/ServerStatusCommand.php +++ b/src/Symfony/Bundle/WebServerBundle/Command/ServerStatusCommand.php @@ -15,6 +15,7 @@ use Symfony\Bundle\WebServerBundle\WebServer; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; /** @@ -44,7 +45,7 @@ class ServerStatusCommand extends ServerCommand */ protected function execute(InputInterface $input, OutputInterface $output) { - $io = new SymfonyStyle($input, $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')))); diff --git a/src/Symfony/Bundle/WebServerBundle/Command/ServerStopCommand.php b/src/Symfony/Bundle/WebServerBundle/Command/ServerStopCommand.php index e461b7ca6b..7bbe2942fb 100644 --- a/src/Symfony/Bundle/WebServerBundle/Command/ServerStopCommand.php +++ b/src/Symfony/Bundle/WebServerBundle/Command/ServerStopCommand.php @@ -14,6 +14,7 @@ namespace Symfony\Bundle\WebServerBundle\Command; use Symfony\Bundle\WebServerBundle\WebServer; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Style\SymfonyStyle; @@ -53,7 +54,7 @@ EOF */ protected function execute(InputInterface $input, OutputInterface $output) { - $io = new SymfonyStyle($input, $output); + $io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output); try { $server = new WebServer();