Skip to content

Commit 196c43b

Browse files
Merge branch '6.0' into 6.1
* 6.0: (22 commits) Add missing license header Add missing license header [Workflow] Catch error when trying to get an uninitialized marking Add missing license header Allow usage of Provider domains if possible Use reference date in reverse transform Fixes #40997 Fix env resolution in lock configuration Fix Symfony not working on SMB share #45990 [Messenger] DoctrineTransportFactory works with notify and decorated PostgreSQL driver [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 Fix use_cookies framework session configuration [FrameworkBundle] [Command] Fix `debug:router --no-interaction` error … [Intl] Update the ICU data to 71.1 - 5.4 [Intl] Update the ICU data to 71.1 - 4.4 Add tests to messenger connection get for OraclePlatform [RateLimiter] Adding default empty value [DependencyInjection] Add TaggedIteratorArgument unit tests ...
2 parents d95603b + ac31f9d commit 196c43b

File tree

6 files changed

+120
-36
lines changed

6 files changed

+120
-36
lines changed

Formatter/NullOutputFormatterStyle.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/*
34
* This file is part of the Symfony package.
45
*

Helper/Table.php

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

322322
$this->calculateNumberOfColumns($rows);
323323

324-
$rows = $this->buildTableRows($rows);
325-
$this->calculateColumnsWidth($rows);
324+
$rowGroups = $this->buildTableRows($rows);
325+
$this->calculateColumnsWidth($rowGroups);
326326

327327
$isHeader = !$this->horizontal;
328328
$isFirstRow = $this->horizontal;
329329
$hasTitle = (bool) $this->headerTitle;
330-
foreach ($rows as $row) {
331-
if ($divider === $row) {
332-
$isHeader = false;
333-
$isFirstRow = true;
334330

335-
continue;
336-
}
337-
if ($row instanceof TableSeparator) {
338-
$this->renderRowSeparator();
331+
foreach ($rowGroups as $rowGroup) {
332+
$isHeaderSeparatorRendered = false;
339333

340-
continue;
341-
}
342-
if (!$row) {
343-
continue;
344-
}
334+
foreach ($rowGroup as $row) {
335+
if ($divider === $row) {
336+
$isHeader = false;
337+
$isFirstRow = true;
345338

346-
if ($isHeader || $isFirstRow) {
347-
$this->renderRowSeparator(
348-
$isHeader ? self::SEPARATOR_TOP : self::SEPARATOR_TOP_BOTTOM,
349-
$hasTitle ? $this->headerTitle : null,
350-
$hasTitle ? $this->style->getHeaderTitleFormat() : null
351-
);
352-
$isFirstRow = false;
353-
$hasTitle = false;
354-
}
355-
if ($this->horizontal) {
356-
$this->renderRow($row, $this->style->getCellRowFormat(), $this->style->getCellHeaderFormat());
357-
} else {
358-
$this->renderRow($row, $isHeader ? $this->style->getCellHeaderFormat() : $this->style->getCellRowFormat());
339+
continue;
340+
}
341+
342+
if ($row instanceof TableSeparator) {
343+
$this->renderRowSeparator();
344+
345+
continue;
346+
}
347+
348+
if (!$row) {
349+
continue;
350+
}
351+
352+
if ($isHeader && !$isHeaderSeparatorRendered) {
353+
$this->renderRowSeparator(
354+
$isHeader ? self::SEPARATOR_TOP : self::SEPARATOR_TOP_BOTTOM,
355+
$hasTitle ? $this->headerTitle : null,
356+
$hasTitle ? $this->style->getHeaderTitleFormat() : null
357+
);
358+
$hasTitle = false;
359+
$isHeaderSeparatorRendered = true;
360+
}
361+
362+
if ($isFirstRow) {
363+
$this->renderRowSeparator(
364+
$isHeader ? self::SEPARATOR_TOP : self::SEPARATOR_TOP_BOTTOM,
365+
$hasTitle ? $this->headerTitle : null,
366+
$hasTitle ? $this->style->getHeaderTitleFormat() : null
367+
);
368+
$isFirstRow = false;
369+
$hasTitle = false;
370+
}
371+
372+
if ($this->horizontal) {
373+
$this->renderRow($row, $this->style->getCellRowFormat(), $this->style->getCellHeaderFormat());
374+
} else {
375+
$this->renderRow($row, $isHeader ? $this->style->getCellHeaderFormat() : $this->style->getCellRowFormat());
376+
}
359377
}
360378
}
361379
$this->renderRowSeparator(self::SEPARATOR_BOTTOM, $this->footerTitle, $this->style->getFooterTitleFormat());
@@ -562,13 +580,14 @@ private function buildTableRows(array $rows): TableRows
562580

563581
return new TableRows(function () use ($rows, $unmergedRows): \Traversable {
564582
foreach ($rows as $rowKey => $row) {
565-
yield $row instanceof TableSeparator ? $row : $this->fillCells($row);
583+
$rowGroup = [$row instanceof TableSeparator ? $row : $this->fillCells($row)];
566584

567585
if (isset($unmergedRows[$rowKey])) {
568586
foreach ($unmergedRows[$rowKey] as $row) {
569-
yield $row instanceof TableSeparator ? $row : $this->fillCells($row);
587+
$rowGroup[] = $row instanceof TableSeparator ? $row : $this->fillCells($row);
570588
}
571589
}
590+
yield $rowGroup;
572591
}
573592
});
574593
}
@@ -709,14 +728,15 @@ private function getRowColumns(array $row): array
709728
/**
710729
* Calculates columns widths.
711730
*/
712-
private function calculateColumnsWidth(iterable $rows)
731+
private function calculateColumnsWidth(iterable $groups)
713732
{
714733
for ($column = 0; $column < $this->numberOfColumns; ++$column) {
715734
$lengths = [];
716-
foreach ($rows as $row) {
717-
if ($row instanceof TableSeparator) {
718-
continue;
719-
}
735+
foreach ($groups as $group) {
736+
foreach ($group as $row) {
737+
if ($row instanceof TableSeparator) {
738+
continue;
739+
}
720740

721741
foreach ($row as $i => $cell) {
722742
if ($cell instanceof TableCell) {
@@ -731,7 +751,8 @@ private function calculateColumnsWidth(iterable $rows)
731751
}
732752
}
733753

734-
$lengths[] = $this->getCellWidth($row, $column);
754+
$lengths[] = $this->getCellWidth($row, $column);
755+
}
735756
}
736757

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

Tests/Command/DumpCompletionCommandTest.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 <[email protected]>
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\Command;
413

514
use PHPUnit\Framework\TestCase;

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 <[email protected]>
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 <[email protected]>
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)