Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aba0d34

Browse files
committed
[Console][Table] fixed render row with multiple cells.
1 parent 9543b36 commit aba0d34

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

src/Symfony/Component/Console/Helper/Table.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ private function buildTableRows($rows)
343343

344344
// Remove any new line breaks and replace it with a new line
345345
foreach ($rows[$rowKey] as $column => $cell) {
346-
$rows[$rowKey] = $this->fillCells($rows[$rowKey], $column);
347346
if (!strstr($cell, "\n")) {
348347
continue;
349348
}
@@ -363,7 +362,7 @@ private function buildTableRows($rows)
363362

364363
$tableRows = array();
365364
foreach ($rows as $rowKey => $row) {
366-
$tableRows[] = $row;
365+
$tableRows[] = $this->fillCells($row);
367366
if (isset($unmergedRows[$rowKey])) {
368367
$tableRows = array_merge($tableRows, $unmergedRows[$rowKey]);
369368
}
@@ -429,21 +428,23 @@ private function fillNextRows($rows, $line)
429428
* fill cells for a row that contains colspan > 1.
430429
*
431430
* @param array $row
432-
* @param int $column
433431
*
434432
* @return array
435433
*/
436-
private function fillCells($row, $column)
434+
private function fillCells($row)
437435
{
438-
$cell = $row[$column];
439-
if ($cell instanceof TableCell && $cell->getColspan() > 1) {
440-
foreach (range($column + 1, $column + $cell->getColspan() - 1) as $position) {
441-
// insert empty value into rows at column position
442-
array_splice($row, $position, 0, '');
436+
$newRow = array();
437+
foreach ($row as $column => $cell) {
438+
$newRow[] = $cell;
439+
if ($cell instanceof TableCell && $cell->getColspan() > 1) {
440+
foreach (range($column + 1, $column + $cell->getColspan() - 1) as $position) {
441+
// insert empty value at column position
442+
$newRow[] = '';
443+
}
443444
}
444445
}
445446

446-
return $row;
447+
return $newRow ?: $row;
447448
}
448449

449450
/**

src/Symfony/Component/Console/Tests/Helper/TableTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,24 @@ public function testRenderProvider()
459459
| ISBN | Title | Author |
460460
+------+-------+--------+
461461
462+
TABLE
463+
),
464+
'Row with multiple cells' => array(
465+
array(),
466+
array(
467+
array(
468+
new TableCell('1', array('colspan' => 3)),
469+
new TableCell('2', array('colspan' => 2)),
470+
new TableCell('3', array('colspan' => 2)),
471+
new TableCell('4', array('colspan' => 2)),
472+
),
473+
),
474+
'default',
475+
<<<TABLE
476+
+--+--+--+--+--+--+--+--+--+
477+
| 1 | 2 | 3 | 4 |
478+
+--+--+--+--+--+--+--+--+--+
479+
462480
TABLE
463481
),
464482
);

0 commit comments

Comments
 (0)