[Console] Decouple SymfonyStyle from TableCell

This commit is contained in:
Roland Franssen 2016-06-24 15:39:41 +00:00 committed by Fabien Potencier
parent fad545aff9
commit 51f59d6f62

View File

@ -17,7 +17,6 @@ use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Helper\SymfonyQuestionHelper; use Symfony\Component\Console\Helper\SymfonyQuestionHelper;
use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Helper\TableCell;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\BufferedOutput; use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@ -218,21 +217,13 @@ class SymfonyStyle extends OutputStyle
*/ */
public function table(array $headers, array $rows) public function table(array $headers, array $rows)
{ {
array_walk_recursive($headers, function (&$value) { $style = clone Table::getStyleDefinition('symfony-style-guide');
if ($value instanceof TableCell) { $style->setCellHeaderFormat('<info>%s</info>');
$value = new TableCell(sprintf('<info>%s</>', $value), array(
'colspan' => $value->getColspan(),
'rowspan' => $value->getRowspan(),
));
} else {
$value = sprintf('<info>%s</>', $value);
}
});
$table = new Table($this); $table = new Table($this);
$table->setHeaders($headers); $table->setHeaders($headers);
$table->setRows($rows); $table->setRows($rows);
$table->setStyle('symfony-style-guide'); $table->setStyle($style);
$table->render(); $table->render();
$this->newLine(); $this->newLine();