File tree 3 files changed +46
-1
lines changed
src/Symfony/Component/Console
Tests/Fixtures/Style/SymfonyStyle
3 files changed +46
-1
lines changed Original file line number Diff line number Diff line change 17
17
use Symfony \Component \Console \Helper \ProgressBar ;
18
18
use Symfony \Component \Console \Helper \SymfonyQuestionHelper ;
19
19
use Symfony \Component \Console \Helper \Table ;
20
+ use Symfony \Component \Console \Helper \TableCell ;
20
21
use Symfony \Component \Console \Input \InputInterface ;
21
22
use Symfony \Component \Console \Output \BufferedOutput ;
22
23
use Symfony \Component \Console \Output \OutputInterface ;
@@ -204,7 +205,16 @@ public function caution($message)
204
205
*/
205
206
public function table (array $ headers , array $ rows )
206
207
{
207
- $ headers = array_map (function ($ value ) { return sprintf ('<info>%s</> ' , $ value ); }, $ headers );
208
+ array_walk_recursive ($ headers , function (&$ value ) {
209
+ if ($ value instanceof TableCell) {
210
+ $ value = new TableCell (sprintf ('<info>%s</> ' , $ value ), array (
211
+ 'colspan ' => $ value ->getColspan (),
212
+ 'rowspan ' => $ value ->getRowspan (),
213
+ ));
214
+ } else {
215
+ $ value = sprintf ('<info>%s</> ' , $ value );
216
+ }
217
+ });
208
218
209
219
$ table = new Table ($ this );
210
220
$ table ->setHeaders ($ headers );
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use Symfony \Component \Console \Input \InputInterface ;
4
+ use Symfony \Component \Console \Output \OutputInterface ;
5
+ use Symfony \Component \Console \Tests \Style \SymfonyStyleWithForcedLineLength ;
6
+ use Symfony \Component \Console \Helper \TableCell ;
7
+
8
+ //Ensure formatting tables when using multiple headers with TableCell
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
+ };
Original file line number Diff line number Diff line change
1
+ ---------------- --------------- ---------------------
2
+ Main table title
3
+ ---------------- --------------- ---------------------
4
+ ISBN Title Author
5
+ ---------------- --------------- ---------------------
6
+ 978-0521567817 De Monarchia Dante Alighieri
7
+ 978-0804169127 Divine Comedy spans multiple rows
8
+ ---------------- --------------- ---------------------
9
+
You can’t perform that action at this time.
0 commit comments