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

Skip to content

Commit f18fd0d

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

File tree

3 files changed

+33
-1
lines changed

3 files changed

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