Skip to content

Commit 2c82847

Browse files
javiereguiluzfabpot
authored andcommitted
Improved the code of the commands that use the new SymfonyStyle class
1 parent 9462624 commit 2c82847

17 files changed

+117
-120
lines changed

Command/CacheClearCommand.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected function configure()
5555
protected function execute(InputInterface $input, OutputInterface $output)
5656
{
5757
$outputIsVerbose = $output->isVerbose();
58-
$output = new SymfonyStyle($input, $output);
58+
$io = new SymfonyStyle($input, $output);
5959

6060
$realCacheDir = $this->getContainer()->getParameter('kernel.cache_dir');
6161
$oldCacheDir = $realCacheDir.'_old';
@@ -70,7 +70,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7070
}
7171

7272
$kernel = $this->getContainer()->get('kernel');
73-
$output->comment(sprintf('Clearing the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
73+
$io->comment(sprintf('Clearing the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
7474
$this->getContainer()->get('cache_clearer')->clear($realCacheDir);
7575

7676
if ($input->getOption('no-warmup')) {
@@ -83,13 +83,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
8383

8484
if ($filesystem->exists($warmupDir)) {
8585
if ($outputIsVerbose) {
86-
$output->comment('Clearing outdated warmup directory...');
86+
$io->comment('Clearing outdated warmup directory...');
8787
}
8888
$filesystem->remove($warmupDir);
8989
}
9090

9191
if ($outputIsVerbose) {
92-
$output->comment('Warming up cache...');
92+
$io->comment('Warming up cache...');
9393
}
9494
$this->warmup($warmupDir, $realCacheDir, !$input->getOption('no-optional-warmers'));
9595

@@ -101,16 +101,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
101101
}
102102

103103
if ($outputIsVerbose) {
104-
$output->comment('Removing old cache directory...');
104+
$io->comment('Removing old cache directory...');
105105
}
106106

107107
$filesystem->remove($oldCacheDir);
108108

109109
if ($outputIsVerbose) {
110-
$output->comment('Finished');
110+
$io->comment('Finished');
111111
}
112112

113-
$output->success(sprintf('Cache for the "%s" environment (debug=%s) was successfully cleared.', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
113+
$io->success(sprintf('Cache for the "%s" environment (debug=%s) was successfully cleared.', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
114114
}
115115

116116
/**

Command/CacheWarmupCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ protected function configure()
5454
*/
5555
protected function execute(InputInterface $input, OutputInterface $output)
5656
{
57-
$output = new SymfonyStyle($input, $output);
57+
$io = new SymfonyStyle($input, $output);
5858

5959
$kernel = $this->getContainer()->get('kernel');
60-
$output->comment(sprintf('Warming up the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
60+
$io->comment(sprintf('Warming up the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
6161

6262
$warmer = $this->getContainer()->get('cache_warmer');
6363

@@ -67,6 +67,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
6767

6868
$warmer->warmUp($this->getContainer()->getParameter('kernel.cache_dir'));
6969

70-
$output->success(sprintf('Cache for the "%s" environment (debug=%s) was successfully warmed.', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
70+
$io->success(sprintf('Cache for the "%s" environment (debug=%s) was successfully warmed.', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
7171
}
7272
}

Command/ConfigDebugCommand.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,16 @@ protected function configure()
5858
*/
5959
protected function execute(InputInterface $input, OutputInterface $output)
6060
{
61-
$output = new SymfonyStyle($input, $output);
61+
$io = new SymfonyStyle($input, $output);
6262
if (false !== strpos($input->getFirstArgument(), ':d')) {
63-
$output->caution('The use of "config:debug" command is deprecated since version 2.7 and will be removed in 3.0. Use the "debug:config" instead.');
63+
$io->caution('The use of "config:debug" command is deprecated since version 2.7 and will be removed in 3.0. Use the "debug:config" instead.');
6464
}
6565

6666
$name = $input->getArgument('name');
6767

6868
if (empty($name)) {
69-
$output->comment('Provide the name of a bundle as the first argument of this command to dump its configuration.');
70-
$output->newLine();
69+
$io->comment('Provide the name of a bundle as the first argument of this command to dump its configuration.');
70+
$io->newLine();
7171
$this->listBundles($output);
7272

7373
return;
@@ -87,12 +87,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
8787
$config = $processor->processConfiguration($configuration, $configs);
8888

8989
if ($name === $extension->getAlias()) {
90-
$output->title(sprintf('Current configuration for extension with alias "%s"', $name));
90+
$io->title(sprintf('Current configuration for extension with alias "%s"', $name));
9191
} else {
92-
$output->title(sprintf('Current configuration for "%s"', $name));
92+
$io->title(sprintf('Current configuration for "%s"', $name));
9393
}
9494

95-
$output->writeln(Yaml::dump(array($extension->getAlias() => $config), 3));
95+
$io->writeln(Yaml::dump(array($extension->getAlias() => $config), 3));
9696
}
9797

9898
private function compileContainer()

Command/ConfigDumpReferenceCommand.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ protected function configure()
6767
*/
6868
protected function execute(InputInterface $input, OutputInterface $output)
6969
{
70-
$output = new SymfonyStyle($input, $output);
70+
$io = new SymfonyStyle($input, $output);
7171
$name = $input->getArgument('name');
7272

7373
if (empty($name)) {
74-
$output->comment('Provide the name of a bundle as the first argument of this command to dump its default configuration.');
75-
$output->newLine();
74+
$io->comment('Provide the name of a bundle as the first argument of this command to dump its default configuration.');
75+
$io->newLine();
7676
$this->listBundles($output);
7777

7878
return;
@@ -92,18 +92,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
9292

9393
switch ($input->getOption('format')) {
9494
case 'yaml':
95-
$output->writeln(sprintf('# %s', $message));
95+
$io->writeln(sprintf('# %s', $message));
9696
$dumper = new YamlReferenceDumper();
9797
break;
9898
case 'xml':
99-
$output->writeln(sprintf('<!-- %s -->', $message));
99+
$io->writeln(sprintf('<!-- %s -->', $message));
100100
$dumper = new XmlReferenceDumper();
101101
break;
102102
default:
103-
$output->writeln($message);
103+
$io->writeln($message);
104104
throw new \InvalidArgumentException('Only the yaml and xml formats are supported.');
105105
}
106106

107-
$output->writeln($dumper->dump($configuration, $extension->getNamespace()));
107+
$io->writeln($dumper->dump($configuration, $extension->getNamespace()));
108108
}
109109
}

Command/ContainerDebugCommand.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ protected function configure()
9494
*/
9595
protected function execute(InputInterface $input, OutputInterface $output)
9696
{
97-
$output = new SymfonyStyle($input, $output);
97+
$io = new SymfonyStyle($input, $output);
9898
if (false !== strpos($input->getFirstArgument(), ':d')) {
99-
$output->caution('The use of "container:debug" command is deprecated since version 2.7 and will be removed in 3.0. Use the "debug:container" instead.');
99+
$io->caution('The use of "container:debug" command is deprecated since version 2.7 and will be removed in 3.0. Use the "debug:container" instead.');
100100
}
101101

102102
$this->validateInput($input);
@@ -129,7 +129,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
129129
$helper->describe($output, $object, $options);
130130

131131
if (!$input->getArgument('name') && $input->isInteractive()) {
132-
$output->comment('To search for a specific service, re-run this command with a search term. (e.g. <comment>debug:container log</comment>)');
132+
$io->comment('To search for a specific service, re-run this command with a search term. (e.g. <comment>debug:container log</comment>)');
133133
}
134134
}
135135

@@ -188,7 +188,7 @@ protected function getContainerBuilder()
188188
return $this->containerBuilder = $container;
189189
}
190190

191-
private function findProperServiceName(InputInterface $input, SymfonyStyle $output, ContainerBuilder $builder, $name)
191+
private function findProperServiceName(InputInterface $input, SymfonyStyle $io, ContainerBuilder $builder, $name)
192192
{
193193
if ($builder->has($name) || !$input->isInteractive()) {
194194
return $name;
@@ -199,7 +199,7 @@ private function findProperServiceName(InputInterface $input, SymfonyStyle $outp
199199
throw new \InvalidArgumentException(sprintf('No services found that match "%s".', $name));
200200
}
201201

202-
return $output->choice('Select one of the following services to display its information', $matchingServices);
202+
return $io->choice('Select one of the following services to display its information', $matchingServices);
203203
}
204204

205205
private function findServiceIdsContaining(ContainerBuilder $builder, $name)

Command/EventDispatcherDebugCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ protected function configure()
5959
*/
6060
protected function execute(InputInterface $input, OutputInterface $output)
6161
{
62-
$output = new SymfonyStyle($input, $output);
62+
$io = new SymfonyStyle($input, $output);
6363
$dispatcher = $this->getEventDispatcher();
6464

6565
$options = array();
6666
if ($event = $input->getArgument('event')) {
6767
if (!$dispatcher->hasListeners($event)) {
68-
$output->warning(sprintf('The event "%s" does not have any registered listeners.', $event));
68+
$io->warning(sprintf('The event "%s" does not have any registered listeners.', $event));
6969

7070
return;
7171
}
@@ -76,8 +76,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
7676
$helper = new DescriptorHelper();
7777
$options['format'] = $input->getOption('format');
7878
$options['raw_text'] = $input->getOption('raw');
79-
$options['output'] = $output;
80-
$helper->describe($output, $dispatcher, $options);
79+
$options['output'] = $io;
80+
$helper->describe($io, $dispatcher, $options);
8181
}
8282

8383
/**

Command/RouterApacheDumperCommand.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,10 @@ protected function configure()
7575
*/
7676
protected function execute(InputInterface $input, OutputInterface $output)
7777
{
78-
$output = new SymfonyStyle($input, $output);
78+
$io = new SymfonyStyle($input, $output);
7979

80-
$output->title('Router Apache Dumper');
81-
82-
$output->caution('The router:dump-apache command is deprecated since version 2.5 and will be removed in 3.0.');
80+
$io->title('Router Apache Dumper');
81+
$io->caution('The router:dump-apache command is deprecated since version 2.5 and will be removed in 3.0.');
8382

8483
$router = $this->getContainer()->get('router');
8584

@@ -93,6 +92,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
9392

9493
$dumper = new ApacheMatcherDumper($router->getRouteCollection());
9594

96-
$output->writeln($dumper->dump($dumpOptions), OutputInterface::OUTPUT_RAW);
95+
$io->writeln($dumper->dump($dumpOptions), OutputInterface::OUTPUT_RAW);
9796
}
9897
}

Command/RouterDebugCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ protected function configure()
7878
*/
7979
protected function execute(InputInterface $input, OutputInterface $output)
8080
{
81-
$output = new SymfonyStyle($input, $output);
81+
$io = new SymfonyStyle($input, $output);
8282

8383
if (false !== strpos($input->getFirstArgument(), ':d')) {
84-
$output->caution('The use of "router:debug" command is deprecated since version 2.7 and will be removed in 3.0. Use the "debug:router" instead.');
84+
$io->caution('The use of "router:debug" command is deprecated since version 2.7 and will be removed in 3.0. Use the "debug:router" instead.');
8585
}
8686

8787
$name = $input->getArgument('name');
@@ -95,11 +95,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
9595

9696
$this->convertController($route);
9797

98-
$helper->describe($output, $route, array(
98+
$helper->describe($io, $route, array(
9999
'format' => $input->getOption('format'),
100100
'raw_text' => $input->getOption('raw'),
101101
'name' => $name,
102-
'output' => $output,
102+
'output' => $io,
103103
));
104104
} else {
105105
$routes = $this->getContainer()->get('router')->getRouteCollection();
@@ -108,11 +108,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
108108
$this->convertController($route);
109109
}
110110

111-
$helper->describe($output, $routes, array(
111+
$helper->describe($io, $routes, array(
112112
'format' => $input->getOption('format'),
113113
'raw_text' => $input->getOption('raw'),
114114
'show_controllers' => $input->getOption('show-controllers'),
115-
'output' => $output,
115+
'output' => $io,
116116
));
117117
}
118118
}

Command/RouterMatchCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected function configure()
7676
*/
7777
protected function execute(InputInterface $input, OutputInterface $output)
7878
{
79-
$output = new SymfonyStyle($input, $output);
79+
$io = new SymfonyStyle($input, $output);
8080

8181
$router = $this->getContainer()->get('router');
8282
$context = $router->getContext();
@@ -94,26 +94,26 @@ protected function execute(InputInterface $input, OutputInterface $output)
9494

9595
$traces = $matcher->getTraces($input->getArgument('path_info'));
9696

97-
$output->newLine();
97+
$io->newLine();
9898

9999
$matches = false;
100100
foreach ($traces as $trace) {
101101
if (TraceableUrlMatcher::ROUTE_ALMOST_MATCHES == $trace['level']) {
102-
$output->text(sprintf('Route <info>"%s"</> almost matches but %s', $trace['name'], lcfirst($trace['log'])));
102+
$io->text(sprintf('Route <info>"%s"</> almost matches but %s', $trace['name'], lcfirst($trace['log'])));
103103
} elseif (TraceableUrlMatcher::ROUTE_MATCHES == $trace['level']) {
104-
$output->success(sprintf('Route "%s" matches', $trace['name']));
104+
$io->success(sprintf('Route "%s" matches', $trace['name']));
105105

106106
$routerDebugCommand = $this->getApplication()->find('debug:router');
107107
$routerDebugCommand->run(new ArrayInput(array('name' => $trace['name'])), $output);
108108

109109
$matches = true;
110110
} elseif ($input->getOption('verbose')) {
111-
$output->text(sprintf('Route "%s" does not match: %s', $trace['name'], $trace['log']));
111+
$io->text(sprintf('Route "%s" does not match: %s', $trace['name'], $trace['log']));
112112
}
113113
}
114114

115115
if (!$matches) {
116-
$output->error(sprintf('None of the routes match the path "%s"', $input->getArgument('path_info')));
116+
$io->error(sprintf('None of the routes match the path "%s"', $input->getArgument('path_info')));
117117

118118
return 1;
119119
}

0 commit comments

Comments
 (0)