bug #14338 [FrameworkBundle] improve usage of Table helper (xabbuh)

This PR was merged into the 2.6 branch.

Discussion
----------

[FrameworkBundle] improve usage of Table helper

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Use the `Table` helper if present in favor of the deprecated
`TableHelper` class.

Commits
-------

71d84e6 [FrameworkBundle] improve usage of Table helper
This commit is contained in:
Fabien Potencier 2015-04-15 17:26:47 +02:00
commit 32db442aef
2 changed files with 22 additions and 5 deletions

View File

@ -12,6 +12,7 @@
namespace Symfony\Bundle\FrameworkBundle\Command;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
@ -28,14 +29,23 @@ abstract class AbstractConfigCommand extends ContainerDebugCommand
{
$output->writeln('Available registered bundles with their extension alias if available:');
$table = $this->getHelperSet()->get('table');
if (class_exists('Symfony\Component\Console\Helper\Table')) {
$table = new Table($output);
} else {
$table = $this->getHelperSet()->get('table');
}
$table->setHeaders(array('Bundle name', 'Extension alias'));
foreach ($this->getContainer()->get('kernel')->getBundles() as $bundle) {
$extension = $bundle->getContainerExtension();
$table->addRow(array($bundle->getName(), $extension ? $extension->getAlias() : ''));
}
$table->render($output);
if (class_exists('Symfony\Component\Console\Helper\Table')) {
$table->render();
} else {
$table->render($output);
}
}
protected function findExtension($name)

View File

@ -131,8 +131,11 @@ EOF
}
}
/** @var \Symfony\Component\Console\Helper\Table $table */
$table = new Table($output);
if (class_exists('Symfony\Component\Console\Helper\Table')) {
$table = new Table($output);
} else {
$table = $this->getHelperSet()->get('table');
}
// Display header line
$headers = array('State(s)', 'Id', sprintf('Message Preview (%s)', $locale));
@ -177,7 +180,11 @@ EOF
}
}
$table->render();
if (class_exists('Symfony\Component\Console\Helper\Table')) {
$table->render();
} else {
$table->render($output);
}
$output->writeln('');
$output->writeln('<info>Legend:</info>');