8000 [Console] Fix array to string conversion when using IO table · symfony/symfony@e522c29 · GitHub
[go: up one dir, main page]

Skip to content

Commit e522c29

Browse files
author
JhonnyL
committed
[Console] Fix array to string conversion when using IO table
1 parent 6400b70 commit e522c29

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

src/Symfony/Component/Console/Style/SymfonyStyle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function caution($message)
204204
*/
205205
public function table(array $headers, array $rows)
206206
{
207-
$headers = array_map(function ($value) { return sprintf('<info>%s</>', $value); }, $headers);
207+
$headers = array_map(function ($value) { return sprintf('<info>%s</>', is_array($value) ? (string) $value[0] : $value); }, $headers);
208208

209209
$table = new Table($this);
210210
$table->setHeaders($headers);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
use Symfony\Component\Console\Helper\Table;
4+
use Symfony\Component\Console\Helper\TableCell;
5+
use Symfony\Component\Console\Input\InputInterface;
6+
use Symfony\Component\Console\Output\OutputInterface;
7+
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
8+
9+
return function (InputInterface $input, OutputInterface $output) {
10+
$headers = array(
11+
array(new TableCell('Main table title', array('colspan' => 3))),
12+
array('ISBN', 'Title', 'Author'),
13+
);
14+
15+
$rows = array(
16+
array(
17+
'978-0521567817',
18+
'De Monarchia',
19+
new TableCell("Dante Alighieri\nspans multiple rows", array('rowspan' => 2)),
20+
),
21+
array('978-0804169127', 'Divine Comedy'),
22+
);
23+
24+
$output = new SymfonyStyleWithForcedLineLength($input, $output);
25+
$output->table($headers, $rows);
26+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
------------------ --------------- ---------------------
2+
Main table title ISBN
3+
------------------ --------------- ---------------------
4+
978-0521567817 De Monarchia Dante Alighieri
5+
978-0804169127 Divine Comedy spans multiple rows
6+
------------------ --------------- ---------------------
7+

0 commit comments

Comments
 (0)
0