diff --git a/src/Symfony/Bridge/Twig/Command/DebugCommand.php b/src/Symfony/Bridge/Twig/Command/DebugCommand.php index d871a682f0..4748444cd1 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..b252ee274c 100644 --- a/src/Symfony/Bridge/Twig/Command/LintCommand.php +++ b/src/Symfony/Bridge/Twig/Command/LintCommand.php @@ -88,9 +88,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..924bd8e92f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php @@ -62,11 +62,12 @@ EOF protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); + $errorIo = $io->getErrorStyle(); 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 +99,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..476813fc36 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php @@ -55,7 +55,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 @@ -73,10 +73,11 @@ EOF protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); + $errorIo = $io->getErrorStyle(); if (null === $name = $input->getArgument('name')) { - $this->listBundles($io); - $io->comment(array( + $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)', )); @@ -94,7 +95,7 @@ EOF $path = $input->getArgument('path'); if ($path !== null && 'yaml' !== $format) { - $io->error('The "path" option is only available for the "yaml" format.'); + $errorIo->error('The "path" option is only available for the "yaml" format.'); return 1; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php index 47f08de6bc..dde5d218b5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php @@ -94,6 +94,8 @@ EOF protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); + $errorIo = $io->getErrorStyle(); + $this->validateInput($input); $object = $this->getContainerBuilder(); @@ -111,7 +113,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 +124,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..ef1c3017fc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/EventDispatcherDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/EventDispatcherDebugCommand.php @@ -65,7 +65,7 @@ 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)); + $io->getErrorStyle()->warning(sprintf('The event "%s" does not have any registered listeners.', $event)); return; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php index 299045d126..79b4234d81 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php @@ -159,7 +159,7 @@ EOF $outputMessage .= sprintf(' and domain "%s"', $domain); } - $io->warning($outputMessage); + $io->getErrorStyle()->warning($outputMessage); return; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php index c2083e034e..f88747cfa6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php @@ -85,10 +85,11 @@ EOF protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); + $errorIo = $io->getErrorStyle(); // check presence of force or dump-message if ($input->getOption('force') !== true && $input->getOption('dump-messages') !== true) { - $io->error('You must choose one of --force or --dump-messages'); + $errorIo->error('You must choose one of --force or --dump-messages'); return 1; } @@ -97,7 +98,7 @@ EOF $writer = $this->getContainer()->get('translation.writer'); $supportedFormats = $writer->getFormats(); if (!in_array($input->getOption('output-format'), $supportedFormats)) { - $io->error(array('Wrong output format', 'Supported formats are: '.implode(', ', $supportedFormats).'.')); + $errorIo->error(array('Wrong output format', 'Supported formats are: '.implode(', ', $supportedFormats).'.')); return 1; } @@ -127,12 +128,12 @@ EOF } } - $io->title('Translation Messages Extractor and Dumper'); - $io->comment(sprintf('Generating "%s" translation files for "%s"', $input->getArgument('locale'), $currentName)); + $errorIo->title('Translation Messages Extractor and Dumper'); + $errorIo->comment(sprintf('Generating "%s" translation files for "%s"', $input->getArgument('locale'), $currentName)); // load any messages from templates $extractedCatalogue = new MessageCatalogue($input->getArgument('locale')); - $io->comment('Parsing templates...'); + $errorIo->comment('Parsing templates...'); $extractor = $this->getContainer()->get('translation.extractor'); $extractor->setPrefix($input->getOption('no-prefix') ? '' : $input->getOption('prefix')); foreach ($transPaths as $path) { @@ -144,7 +145,7 @@ EOF // load any existing messages from the translation files $currentCatalogue = new MessageCatalogue($input->getArgument('locale')); - $io->comment('Loading translation files...'); + $errorIo->comment('Loading translation files...'); $loader = $this->getContainer()->get('translation.loader'); foreach ($transPaths as $path) { $path .= 'translations'; @@ -165,7 +166,7 @@ EOF // Exit if no messages found. if (!count($operation->getDomains())) { - $io->warning('No translation messages were found.'); + $errorIo->warning('No translation messages were found.'); return; } @@ -199,7 +200,7 @@ EOF } if ($input->getOption('output-format') == 'xlf') { - $io->comment('Xliff output version is 1.2'); + $errorIo->comment('Xliff output version is 1.2'); } $resultMessage = sprintf('%d message%s successfully extracted', $extractedMessagesCount, $extractedMessagesCount > 1 ? 's were' : ' was'); @@ -211,7 +212,7 @@ EOF // save the files if ($input->getOption('force') === true) { - $io->comment('Writing files...'); + $errorIo->comment('Writing files...'); $bundleTransPath = false; foreach ($transPaths as $path) { @@ -232,7 +233,7 @@ EOF } } - $io->success($resultMessage.'.'); + $errorIo->success($resultMessage.'.'); } private function filterCatalogue(MessageCatalogue $catalogue, $domain) diff --git a/src/Symfony/Bundle/SecurityBundle/Command/UserPasswordEncoderCommand.php b/src/Symfony/Bundle/SecurityBundle/Command/UserPasswordEncoderCommand.php index d6e689daa1..a588bdd331 100644 --- a/src/Symfony/Bundle/SecurityBundle/Command/UserPasswordEncoderCommand.php +++ b/src/Symfony/Bundle/SecurityBundle/Command/UserPasswordEncoderCommand.php @@ -15,6 +15,7 @@ use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\Question; use Symfony\Component\Console\Style\SymfonyStyle; @@ -114,8 +115,9 @@ EOF protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); + $errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io; - $input->isInteractive() ? $io->title('Symfony Password Encoder Utility') : $io->newLine(); + $input->isInteractive() ? $errorIo->title('Symfony Password Encoder Utility') : $errorIo->newLine(); $password = $input->getArgument('password'); $userClass = $this->getUserClass($input, $io); @@ -131,12 +133,12 @@ EOF if (!$password) { if (!$input->isInteractive()) { - $io->error('The password must not be empty.'); + $errorIo->error('The password must not be empty.'); return 1; } $passwordQuestion = $this->createPasswordQuestion(); - $password = $io->askQuestion($passwordQuestion); + $password = $errorIo->askQuestion($passwordQuestion); } $salt = null; @@ -144,9 +146,9 @@ EOF if ($input->isInteractive() && !$emptySalt) { $emptySalt = true; - $io->note('The command will take care of generating a salt for you. Be aware that some encoders advise to let them generate their own salt. If you\'re using one of those encoders, please answer \'no\' to the question below. '.PHP_EOL.'Provide the \'empty-salt\' option in order to let the encoder handle the generation itself.'); + $errorIo->note('The command will take care of generating a salt for you. Be aware that some encoders advise to let them generate their own salt. If you\'re using one of those encoders, please answer \'no\' to the question below. '.PHP_EOL.'Provide the \'empty-salt\' option in order to let the encoder handle the generation itself.'); - if ($io->confirm('Confirm salt generation ?')) { + if ($errorIo->confirm('Confirm salt generation ?')) { $salt = $this->generateSalt(); $emptySalt = false; } @@ -166,12 +168,12 @@ EOF $io->table(array('Key', 'Value'), $rows); if (!$emptySalt) { - $io->note(sprintf('Make sure that your salt storage field fits the salt length: %s chars', strlen($salt))); + $errorIo->note(sprintf('Make sure that your salt storage field fits the salt length: %s chars', strlen($salt))); } elseif ($bcryptWithoutEmptySalt) { - $io->note('Bcrypt encoder used: the encoder generated its own built-in salt.'); + $errorIo->note('Bcrypt encoder used: the encoder generated its own built-in salt.'); } - $io->success('Password encoding succeeded'); + $errorIo->success('Password encoding succeeded'); } /** diff --git a/src/Symfony/Bundle/WebServerBundle/Command/ServerRunCommand.php b/src/Symfony/Bundle/WebServerBundle/Command/ServerRunCommand.php index 0ec26d2559..cfedd30957 100644 --- a/src/Symfony/Bundle/WebServerBundle/Command/ServerRunCommand.php +++ b/src/Symfony/Bundle/WebServerBundle/Command/ServerRunCommand.php @@ -80,7 +80,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();