function Table::buildTableRows
2 calls to Table::buildTableRows()
- Table::calculateRowCount in vendor/
symfony/ console/ Helper/ Table.php - Table::render in vendor/
symfony/ console/ Helper/ Table.php - Renders table to output.
File
-
vendor/
symfony/ console/ Helper/ Table.php, line 617
Class
- Table
- Provides helpers to display a table.
Namespace
Symfony\Component\Console\HelperCode
private function buildTableRows(array $rows) : TableRows {
/** @var WrappableOutputFormatterInterface $formatter */
$formatter = $this->output
->getFormatter();
$unmergedRows = [];
for ($rowKey = 0; $rowKey < \count($rows); ++$rowKey) {
$rows = $this->fillNextRows($rows, $rowKey);
// Remove any new line breaks and replace it with a new line
foreach ($rows[$rowKey] as $column => $cell) {
$colspan = $cell instanceof TableCell ? $cell->getColspan() : 1;
if (isset($this->columnMaxWidths[$column]) && Helper::width(Helper::removeDecoration($formatter, $cell)) > $this->columnMaxWidths[$column]) {
$cell = $formatter->formatAndWrap($cell, $this->columnMaxWidths[$column] * $colspan);
}
if (!str_contains($cell ?? '', "\n")) {
continue;
}
$eol = str_contains($cell ?? '', "\r\n") ? "\r\n" : "\n";
$escaped = implode($eol, array_map(OutputFormatter::escapeTrailingBackslash(...), explode($eol, $cell)));
$cell = $cell instanceof TableCell ? new TableCell($escaped, [
'colspan' => $cell->getColspan(),
]) : $escaped;
$lines = explode($eol, str_replace($eol, '<fg=default;bg=default></>' . $eol, $cell));
foreach ($lines as $lineKey => $line) {
if ($colspan > 1) {
$line = new TableCell($line, [
'colspan' => $colspan,
]);
}
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;
}
}
}
}
return new TableRows(function () use ($rows, $unmergedRows) : \Traversable {
foreach ($rows as $rowKey => $row) {
$rowGroup = [
$row instanceof TableSeparator ? $row : $this->fillCells($row),
];
if (isset($unmergedRows[$rowKey])) {
foreach ($unmergedRows[$rowKey] as $row) {
$rowGroup[] = $row instanceof TableSeparator ? $row : $this->fillCells($row);
}
}
(yield $rowGroup);
}
});
}