Page MenuHomeDevCentral

MarkdownOutput.php
No OneTemporary

MarkdownOutput.php

<?php
namespace Keruald\Reporting\Output;
class MarkdownOutput extends Output {
public function render () : string {
$send = [];
if ($this->report->sections || $this->report->properties
|| $this->report->title) {
$send[] = '# ' . $this->report->title;
$send[] = '';
foreach ($this->report->sections as $section) {
$send[] = '## ' . $section->title;
$send[] = '';
foreach ($section->entries as $entry) {
$send[] = '### ' . $entry->title;
$send[] = '';
$send[] = $entry->text;
$send[] = '';
}
}
if ($this->report->properties && $this->report->sections) {
$send[] = '---';
$send[] = '';
}
if ($this->report->properties) {
$properties = $this->report->properties;
$propertyMaxLength = 0;
$maxValue = 0;
foreach ($properties as $key => $value) {
$propertyMaxLength = max($propertyMaxLength, strlen($key));
$maxValue = max($maxValue, strlen($value));
}
if ($propertyMaxLength < 8) {
$propertyMaxLength = 8;
}
$send[] =
'| Property' . str_repeat(' ', $propertyMaxLength - 8)
. ' | '
. str_repeat(' ', $maxValue) . ' |';
$send[] = '|' . str_repeat('-', $propertyMaxLength + 2) . '|'
. str_repeat('-', $maxValue + 2) . '|';
foreach ($properties as $key => $value) {
$send[] =
'| ' . $key . str_repeat(' ',
$propertyMaxLength - strlen($key))
. ' | '
. $value . str_repeat(' ', $maxValue - strlen($value))
. ' |';
}
$send[] = '';
}
}
return implode("\n", $send);
}
}

File Metadata

Mime Type
text/x-php
Expires
Sun, Oct 12, 05:23 (1 d, 8 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3063842
Default Alt Text
MarkdownOutput.php (2 KB)

Event Timeline