diff --git a/src/Symfony/Bridge/Twig/Command/DebugCommand.php b/src/Symfony/Bridge/Twig/Command/DebugCommand.php index 44e23902e03de..061cd82162a47 100644 --- a/src/Symfony/Bridge/Twig/Command/DebugCommand.php +++ b/src/Symfony/Bridge/Twig/Command/DebugCommand.php @@ -87,9 +87,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $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 ebbfde12c2058..b252ee274cd57 100644 --- a/src/Symfony/Bridge/Twig/Command/LintCommand.php +++ b/src/Symfony/Bridge/Twig/Command/LintCommand.php @@ -88,9 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $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 921dba0dde977..924bd8e92f659 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php @@ -62,11 +62,12 @@ protected function configure() 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 @@ protected function execute(InputInterface $input, OutputInterface $output) 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 574b496c727bb..476813fc3621e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php @@ -55,7 +55,7 @@ protected function configure() 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 @@ protected function configure() 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 @@ protected function execute(InputInterface $input, OutputInterface $output) $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 47f08de6bcad7..dde5d218b5af0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php @@ -94,6 +94,8 @@ protected function configure() 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 @@ protected function execute(InputInterface $input, OutputInterface $output) } 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 @@ protected function execute(InputInterface $input, OutputInterface $output) $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 2eb310ddf1701..ef1c3017fca28 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/EventDispatcherDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/EventDispatcherDebugCommand.php @@ -65,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $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 299045d126b32..79b4234d81eb8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php @@ -159,7 +159,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $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 c2083e034e32c..f88747cfa61f8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php @@ -85,10 +85,11 @@ public function isEnabled() 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 @@ protected function execute(InputInterface $input, OutputInterface $output) $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 @@ protected function execute(InputInterface $input, OutputInterface $output) } } - $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 @@ protected function execute(InputInterface $input, OutputInterface $output) // 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 @@ protected function execute(InputInterface $input, OutputInterface $output) // 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 @@ protected function execute(InputInterface $input, OutputInterface $output) } 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 @@ protected function execute(InputInterface $input, OutputInterface $output) // 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 @@ protected function execute(InputInterface $input, OutputInterface $output) } } - $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 7151175d938e7..f9986ba9beba7 100644 --- a/src/Symfony/Bundle/SecurityBundle/Command/UserPasswordEncoderCommand.php +++ b/src/Symfony/Bundle/SecurityBundle/Command/UserPasswordEncoderCommand.php @@ -15,6 +15,7 @@ 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; @@ -85,8 +86,9 @@ protected function configure() 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 = $input->getArgument('user-class'); @@ -101,12 +103,12 @@ protected function execute(InputInterface $input, OutputInterface $output) 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; @@ -114,9 +116,9 @@ protected function execute(InputInterface $input, OutputInterface $output) 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; } @@ -136,12 +138,12 @@ protected function execute(InputInterface $input, OutputInterface $output) $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 4259e0071314a..2dd8cacaaded7 100644 --- a/src/Symfony/Bundle/WebServerBundle/Command/ServerRunCommand.php +++ b/src/Symfony/Bundle/WebServerBundle/Command/ServerRunCommand.php @@ -79,7 +79,7 @@ protected function configure() */ 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 a490802472f9a..c0888e944e136 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\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 @@ protected function configure() */ 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 @@ protected function execute(InputInterface $input, OutputInterface $output) )); 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 c77f2f755f646..91ec0d2958486 100644 --- a/src/Symfony/Bundle/WebServerBundle/Command/ServerStatusCommand.php +++ b/src/Symfony/Bundle/WebServerBundle/Command/ServerStatusCommand.php @@ -15,6 +15,7 @@ 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 @@ protected function configure() */ 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 e461b7ca6b46c..7bbe2942fb906 100644 --- a/src/Symfony/Bundle/WebServerBundle/Command/ServerStopCommand.php +++ b/src/Symfony/Bundle/WebServerBundle/Command/ServerStopCommand.php @@ -14,6 +14,7 @@ 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 @@ protected function configure() */ 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();