[Console] Table: support cells with newlines after a cell with colspan >= 2
This commit is contained in:
parent
909158bdb7
commit
ca11772e3f
@ -574,6 +574,9 @@ class Table
|
||||
if (0 === $lineKey) {
|
||||
$rows[$rowKey][$column] = $line;
|
||||
} else {
|
||||
if (!\array_key_exists($rowKey, $unmergedRows) || !\array_key_exists($lineKey, $unmergedRows[$rowKey])) {
|
||||
$unmergedRows[$rowKey][$lineKey] = $this->copyRow($rows, $rowKey);
|
||||
}
|
||||
$unmergedRows[$rowKey][$lineKey][$column] = $line;
|
||||
}
|
||||
}
|
||||
@ -585,8 +588,8 @@ class Table
|
||||
yield $this->fillCells($row);
|
||||
|
||||
if (isset($unmergedRows[$rowKey])) {
|
||||
foreach ($unmergedRows[$rowKey] as $row) {
|
||||
yield $row;
|
||||
foreach ($unmergedRows[$rowKey] as $unmergedRow) {
|
||||
yield $this->fillCells($unmergedRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -670,12 +673,17 @@ class Table
|
||||
private function fillCells($row)
|
||||
{
|
||||
$newRow = [];
|
||||
|
||||
$newColumn = null;
|
||||
foreach ($row as $column => $cell) {
|
||||
$newRow[] = $cell;
|
||||
if (null === $newColumn) {
|
||||
$newColumn = $column;
|
||||
}
|
||||
$newRow[$newColumn++] = $cell;
|
||||
if ($cell instanceof TableCell && $cell->getColspan() > 1) {
|
||||
foreach (range($column + 1, $column + $cell->getColspan() - 1) as $position) {
|
||||
// insert empty value at column position
|
||||
$newRow[] = '';
|
||||
$newRow[$newColumn++] = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -333,6 +333,45 @@ TABLE
|
||||
| Cupiditate dicta atque porro, tempora exercitationem modi animi nulla nemo vel nihil! |
|
||||
+-------------------------------+-------------------------------+-----------------------------+
|
||||
|
||||
TABLE
|
||||
],
|
||||
'Cell after colspan contains new line break' => [
|
||||
['Foo', 'Bar', 'Baz'],
|
||||
[
|
||||
[
|
||||
new TableCell("foo\nbar", ['colspan' => 2]),
|
||||
"baz\nqux",
|
||||
],
|
||||
],
|
||||
'default',
|
||||
<<<'TABLE'
|
||||
+-----+-----+-----+
|
||||
| Foo | Bar | Baz |
|
||||
+-----+-----+-----+
|
||||
| foo | baz |
|
||||
| bar | qux |
|
||||
+-----+-----+-----+
|
||||
|
||||
TABLE
|
||||
],
|
||||
'Cell after colspan contains multiple new lines' => [
|
||||
['Foo', 'Bar', 'Baz'],
|
||||
[
|
||||
[
|
||||
new TableCell("foo\nbar", ['colspan' => 2]),
|
||||
"baz\nqux\nquux",
|
||||
],
|
||||
],
|
||||
'default',
|
||||
<<<'TABLE'
|
||||
+-----+-----+------+
|
||||
| Foo | Bar | Baz |
|
||||
+-----+-----+------+
|
||||
| foo | baz |
|
||||
| bar | qux |
|
||||
| | quux |
|
||||
+-----+-----+------+
|
||||
|
||||
TABLE
|
||||
],
|
||||
'Cell with rowspan' => [
|
||||
|
Reference in New Issue
Block a user