Repository navigation
Expand file tree
/
Copy pathTable.php
More file actions
71 lines (62 loc) · 2.14 KB
/
Copy pathTable.php
File metadata and controls
71 lines (62 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
declare(strict_types=1);
namespace PHPForge\Debug\Helper;
use PHPForge\Debug\Theme\Css;
use UIAwesome\Html\Flow\Div;
use UIAwesome\Html\Table\{Table as HtmlTable, Tbody, Th, Thead, Tr};
/**
* Builds the shared debugger table shell: an optional column-header row above the body rows, inside a scroll wrapper.
*/
final class Table
{
/**
* Builds the `<table>` element, prepending a `<thead>` row of `<th scope="col">` cells when labels are supplied.
*
* Exposed on its own so sections that decorate the shell (extra attributes, a fixed layout) still share one
* header and body contract.
*
* @param list<string> $headers Column labels, or `[]` for a table without a header row.
* @param list<Tr> $rows Body rows in display order.
* @param string $class Table CSS classes.
*
* @return HtmlTable Table element.
*/
public static function build(array $headers, array $rows, string $class = Css::TABLE): HtmlTable
{
$table = HtmlTable::tag()->class($class);
if ($headers === []) {
return $table->html(Tbody::tag()->html(...$rows));
}
$cells = [];
foreach ($headers as $header) {
$cells[] = Th::tag()
->scope('col')
->content($header);
}
return $table->html(
Thead::tag()->html(Tr::tag()->html(...$cells)),
Tbody::tag()->html(...$rows),
);
}
/**
* Renders the table shell inside its scroll wrapper.
*
* @param list<string> $headers Column labels, or `[]` for a table without a header row.
* @param list<Tr> $rows Body rows in display order.
* @param string $tableClass Table CSS classes.
* @param string $wrapClass Scroll-wrapper CSS classes.
*
* @return string Wrapped table markup.
*/
public static function render(
array $headers,
array $rows,
string $tableClass = Css::TABLE,
string $wrapClass = Css::TABLE_WRAP,
): string {
return Div::tag()
->class($wrapClass)
->html(self::build($headers, $rows, $tableClass))
->render();
}
}