3 namespace Keruald\Reporting\Output
;
5 class HTMLOutput
extends Output
{
7 private function makeId ($name) : string {
8 return urlencode(strtolower(str_replace(' ', '-', $name)));
11 private static function encode (string $text) : string {
12 return htmlspecialchars($text);
15 public function render () : string {
18 $title = $this->report
->title
;
20 '<h1 id="' . $this->makeId($title) . '">' . self
::encode($title)
23 foreach ($this->report
->sections
as $section) {
24 $title = $section->title
;
26 '<h2 id="' . $this->makeId($title) . '">' .
27 self
::encode($title) . '</h2>';
28 foreach ($section->entries
as $entry) {
29 $title = $entry->title
;
30 $send[] = '<h3 id="' . $this->makeId($title) . '">' .
31 self
::encode($title) . '</h3>';
33 $text = explode("\n\n", $entry->text
);
35 foreach ($text as $value) {
36 $send[] = '<p>' . self
::encode($value) . '</p>';
42 $send[] = '<h2 id="report-properties">Report properties</h2>';
44 $send[] = str_repeat(" ", 4) . '<tbody>';
46 $properties = $this->report
->properties
;
48 foreach ($properties as $key => $value) {
49 $send[] = str_repeat(" ", 4) . '<tr>';
50 $send[] = str_repeat(" ", 8) .
52 '<th>' . self
::encode($key) . '</th>';
53 $send[] = str_repeat(" ", 8) .
54 '<td>' . self
::encode($value) . '</td>';
56 $send[] = str_repeat(" ", 4) . '</tr>';
58 $send[] = str_repeat(" ", 4) . '</tbody>';
62 return implode("\n", $send);