Skip to content

Commit 5a2d0d4

Browse files
Merge branch '4.4' into 5.4
* 4.4: [Workflow] Catch error when trying to get an uninitialized marking Add missing license header Use reference date in reverse transform Fixes #40997 Fix env resolution in lock configuration Fix Symfony not working on SMB share #45990 [Cache] make LockRegistry use static properties instead of static variables fix: return-path has higher priority for envelope address than from address (fixes #41322) [HttpClient] Fix sending content-length when streaming the body [Console] Header with column max width is now well wrap with separator [DependencyInjection] Add TaggedIteratorArgument unit tests
2 parents 9002752 + 0e1e620 commit 5a2d0d4

File tree

4 files changed

+110
-36
lines changed

4 files changed

+110
-36
lines changed

Helper/Table.php

Lines changed: 57 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -383,41 +383,59 @@ public function render()
383383

384384
$this->calculateNumberOfColumns($rows);
385385

386-
$rows = $this->buildTableRows($rows);
387-
$this->calculateColumnsWidth($rows);
386+
$rowGroups = $this->buildTableRows($rows);
387+
$this->calculateColumnsWidth($rowGroups);
388388

389389
$isHeader = !$this->horizontal;
390390
$isFirstRow = $this->horizontal;
391391
$hasTitle = (bool) $this->headerTitle;
392-
foreach ($rows as $row) {
393-
if ($divider === $row) {
394-
$isHeader = false;
395-
$isFirstRow = true;
396392

397-
continue;
398-
}
399-
if ($row instanceof TableSeparator) {
400-
$this->renderRowSeparator();
393+
foreach ($rowGroups as $rowGroup) {
394+
$isHeaderSeparatorRendered = false;
401395

402-
continue;
403-
}
404-
if (!$row) {
405-
continue;
406-
}
396+
foreach ($rowGroup as $row) {
397+
if ($divider === $row) {
398+
$isHeader = false;
399+
$isFirstRow = true;
407400

408-
if ($isHeader || $isFirstRow) {
409-
$this->renderRowSeparator(
410-
$isHeader ? self::SEPARATOR_TOP : self::SEPARATOR_TOP_BOTTOM,
411-
$hasTitle ? $this->headerTitle : null,
412-
$hasTitle ? $this->style->getHeaderTitleFormat() : null
413-
);
414-
$isFirstRow = false;
415-
$hasTitle = false;
416-
}
417-
if ($this->horizontal) {
418-
$this->renderRow($row, $this->style->getCellRowFormat(), $this->style->getCellHeaderFormat());
419-
} else {
420-
$this->renderRow($row, $isHeader ? $this->style->getCellHeaderFormat() : $this->style->getCellRowFormat());
401+
continue;
402+
}
403+
404+
if ($row instanceof TableSeparator) {
405+
$this->renderRowSeparator();
406+
407+
continue;
408+
}
409+
410+
if (!$row) {
411+
continue;
412+
}
413+
414+
if ($isHeader && !$isHeaderSeparatorRendered) {
415+
$this->renderRowSeparator(
416+
$isHeader ? self::SEPARATOR_TOP : self::SEPARATOR_TOP_BOTTOM,
417+
$hasTitle ? $this->headerTitle : null,
418+
$hasTitle ? $this->style->getHeaderTitleFormat() : null
419+
);
420+
$hasTitle = false;
421+
$isHeaderSeparatorRendered = true;
422+
}
423+
424+
if ($isFirstRow) {
425+
$this->renderRowSeparator(
426+
$isHeader ? self::SEPARATOR_TOP : self::SEPARATOR_TOP_BOTTOM,
427+
$hasTitle ? $this->headerTitle : null,
428+
$hasTitle ? $this->style->getHeaderTitleFormat() : null
429+
);
430+
$isFirstRow = false;
431+
$hasTitle = false;
432+
}
433+
434+
if ($this->horizontal) {
435+
$this->renderRow($row, $this->style->getCellRowFormat(), $this->style->getCellHeaderFormat());
436+
} else {
437+
$this->renderRow($row, $isHeader ? $this->style->getCellHeaderFormat() : $this->style->getCellRowFormat());
438+
}
421439
}
422440
}
423441
$this->renderRowSeparator(self::SEPARATOR_BOTTOM, $this->footerTitle, $this->style->getFooterTitleFormat());
@@ -624,13 +642,14 @@ private function buildTableRows(array $rows): TableRows
624642

625643
return new TableRows(function () use ($rows, $unmergedRows): \Traversable {
626644
foreach ($rows as $rowKey => $row) {
627-
yield $row instanceof TableSeparator ? $row : $this->fillCells($row);
645+
$rowGroup = [$row instanceof TableSeparator ? $row : $this->fillCells($row)];
628646

629647
if (isset($unmergedRows[$rowKey])) {
630648
foreach ($unmergedRows[$rowKey] as $row) {
631-
yield $row instanceof TableSeparator ? $row : $this->fillCells($row);
649+
$rowGroup[] = $row instanceof TableSeparator ? $row : $this->fillCells($row);
632650
}
633651
}
652+
yield $rowGroup;
634653
}
635654
});
636655
}
@@ -771,14 +790,15 @@ private function getRowColumns(array $row): array
771790
/**
772791
* Calculates columns widths.
773792
*/
774-
private function calculateColumnsWidth(iterable $rows)
793+
private function calculateColumnsWidth(iterable $groups)
775794
{
776795
for ($column = 0; $column < $this->numberOfColumns; ++$column) {
777796
$lengths = [];
778-
foreach ($rows as $row) {
779-
if ($row instanceof TableSeparator) {
780-
continue;
781-
}
797+
foreach ($groups as $group) {
798+
foreach ($group as $row) {
799+
if ($row instanceof TableSeparator) {
800+
continue;
801+
}
782802

783803
foreach ($row as $i => $cell) {
784804
if ($cell instanceof TableCell) {
@@ -793,7 +813,8 @@ private function calculateColumnsWidth(iterable $rows)
793813
}
794814
}
795815

796-
$lengths[] = $this->getCellWidth($row, $column);
816+
$lengths[] = $this->getCellWidth($row, $column);
817+
}
797818
}
798819

799820
$this->effectiveColumnWidths[$column] = max($lengths) + Helper::width($this->style->getCellRowContentFormat()) - 2;

Tests/Helper/ProgressIndicatorTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\Console\Tests\Helper;
413

514
use PHPUnit\Framework\TestCase;

Tests/Helper/SymfonyQuestionHelperTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\Console\Tests\Helper;
413

514
use Symfony\Component\Console\Exception\RuntimeException;

Tests/Helper/TableTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,41 @@ public function testColumnMaxWidths()
13651365
| | ities | | |
13661366
+---------------+-------+------------+-----------------+
13671367
1368+
TABLE;
1369+
1370+
$this->assertEquals($expected, $this->getOutputContent($output));
1371+
}
1372+
1373+
public function testColumnMaxWidthsHeaders()
1374+
{
1375+
$table = new Table($output = $this->getOutputStream());
1376+
$table
1377+
->setHeaders([
1378+
[
1379+
'Publication',
1380+
'Very long header with a lot of information',
1381+
],
1382+
])
1383+
->setRows([
1384+
[
1385+
'1954',
1386+
'The Lord of the Rings, by J.R.R. Tolkien',
1387+
],
1388+
])
1389+
->setColumnMaxWidth(1, 30);
1390+
1391+
$table->render();
1392+
1393+
$expected =
1394+
<<<TABLE
1395+
+-------------+--------------------------------+
1396+
| Publication | Very long header with a lot of |
1397+
| | information |
1398+
+-------------+--------------------------------+
1399+
| 1954 | The Lord of the Rings, by J.R. |
1400+
| | R. Tolkien |
1401+
+-------------+--------------------------------+
1402+
13681403
TABLE;
13691404

13701405
$this->assertEquals($expected, $this->getOutputContent($output));

0 commit comments

Comments
 (0)