Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12241569
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
12 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/Output/HTMLOutput.php b/src/Output/HTMLOutput.php
index a722205..d916c9a 100644
--- a/src/Output/HTMLOutput.php
+++ b/src/Output/HTMLOutput.php
@@ -1,64 +1,72 @@
<?php
namespace Keruald\Reporting\Output;
class HTMLOutput extends Output {
private function makeId ($name) : string {
return urlencode(strtolower(str_replace(' ', '-', $name)));
}
private static function encode (string $text) : string {
return htmlspecialchars($text);
}
public function render () : string {
$send = [];
- $title = $this->report->title;
- $send[] =
- '<h1 id="' . $this->makeId($title) . '">' . self::encode($title)
- . '</h1>';
+ if ($this->report->sections || $this->report->properties
+ || $this->report->title) {
- foreach ($this->report->sections as $section) {
- $title = $section->title;
+ $title = $this->report->title;
$send[] =
- '<h2 id="' . $this->makeId($title) . '">' .
- self::encode($title) . '</h2>';
- foreach ($section->entries as $entry) {
- $title = $entry->title;
- $send[] = '<h3 id="' . $this->makeId($title) . '">' .
- self::encode($title) . '</h3>';
+ '<h1 id="' . $this->makeId($title) . '">' . self::encode($title)
+ . '</h1>';
+ if ($this->report->sections) {
+ foreach ($this->report->sections as $section) {
+ $title = $section->title;
+ $send[] =
+ '<h2 id="' . $this->makeId($title) . '">' .
+ self::encode($title) . '</h2>';
+ foreach ($section->entries as $entry) {
+ $title = $entry->title;
+ $send[] = '<h3 id="' . $this->makeId($title) . '">' .
+ self::encode($title) . '</h3>';
- $text = explode("\n\n", $entry->text);
+ $text = explode("\n\n", $entry->text);
- foreach ($text as $value) {
- $send[] = '<p>' . self::encode($value) . '</p>';
+ foreach ($text as $value) {
+ $send[] = '<p>' . self::encode($value) . '</p>';
+ }
+ }
+ }
+ if ($this->report->properties && $this->report->sections) {
+ $send[] = '<hr>';
}
}
- }
- $send[] = '<hr>';
-
- $send[] = '<h2 id="report-properties">Report properties</h2>';
- $send[] = '<table>';
- $send[] = str_repeat(" ", 4) . '<tbody>';
+ if ($this->report->properties) {
+ $send[] = '<h2 id="report-properties">Report properties</h2>';
+ $send[] = '<table>';
+ $send[] = str_repeat(" ", 4) . '<tbody>';
- $properties = $this->report->properties;
+ $properties = $this->report->properties;
- foreach ($properties as $key => $value) {
- $send[] = str_repeat(" ", 4) . '<tr>';
- $send[] = str_repeat(" ", 8) .
+ foreach ($properties as $key => $value) {
+ $send[] = str_repeat(" ", 4) . '<tr>';
+ $send[] = str_repeat(" ", 8) .
- '<th>' . self::encode($key) . '</th>';
- $send[] = str_repeat(" ", 8) .
- '<td>' . self::encode($value) . '</td>';
+ '<th>' . self::encode($key) . '</th>';
+ $send[] = str_repeat(" ", 8) .
+ '<td>' . self::encode($value) . '</td>';
- $send[] = str_repeat(" ", 4) . '</tr>';
+ $send[] = str_repeat(" ", 4) . '</tr>';
+ }
+ $send[] = str_repeat(" ", 4) . '</tbody>';
+ $send[] = '</table>';
+ }
}
- $send[] = str_repeat(" ", 4) . '</tbody>';
- $send[] = '</table>';
$send[] = '';
return implode("\n", $send);
}
}
diff --git a/src/Output/MarkdownOutput.php b/src/Output/MarkdownOutput.php
index b9dfcb3..ad0020b 100644
--- a/src/Output/MarkdownOutput.php
+++ b/src/Output/MarkdownOutput.php
@@ -1,53 +1,68 @@
<?php
namespace Keruald\Reporting\Output;
class MarkdownOutput extends Output {
public function render () : string {
$send = [];
- $send[] = '# ' . $this->report->title;
- $send[] = '';
- foreach ($this->report->sections as $section) {
- $send[] = '## ' . $section->title;
+ if ($this->report->sections || $this->report->properties
+ || $this->report->title) {
+
+ $send[] = '# ' . $this->report->title;
$send[] = '';
- foreach ($section->entries as $entry) {
- $send[] = '### ' . $entry->title;
+ foreach ($this->report->sections as $section) {
+ $send[] = '## ' . $section->title;
$send[] = '';
- $send[] = $entry->text;
+ 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[] = '---';
- $send[] = '';
- $properties = $this->report->properties;
- $propertyMaxLength = 0;
- $maxValue = 0;
- foreach ($properties as $key => $value) {
- $propertyMaxLength = max($propertyMaxLength, strlen($key));
- $maxValue = max($maxValue, strlen($value));
- }
- $propertyMaxLength = max(8, $propertyMaxLength);
+ $send[] =
+ '| Property' . str_repeat(' ', $propertyMaxLength - 8)
+ . ' | '
+ . str_repeat(' ', $maxValue) . ' |';
- $send[] = '| Property' . str_repeat(' ', $propertyMaxLength - 8) . ' | '
- . str_repeat(' ', $maxValue) . ' |';
+ $send[] = '|' . str_repeat('-', $propertyMaxLength + 2) . '|'
+ . str_repeat('-', $maxValue + 2) . '|';
- $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))
+ . ' |';
+ }
- foreach ($properties as $key => $value) {
- $send[] =
- '| ' . $key . str_repeat(' ', $propertyMaxLength - strlen($key))
- . ' | '
- . $value . str_repeat(' ', $maxValue - strlen($value)) . ' |';
+ $send[] = '';
+ }
}
- $send[] = '';
-
return implode("\n", $send);
}
}
diff --git a/src/Output/XMLOutput.php b/src/Output/XMLOutput.php
index 48b547d..c118198 100644
--- a/src/Output/XMLOutput.php
+++ b/src/Output/XMLOutput.php
@@ -1,71 +1,80 @@
<?php
namespace Keruald\Reporting\Output;
class XMLOutput extends Output {
public function render () : string {
$document = xmlwriter_open_memory();
xmlwriter_set_indent($document, true);
xmlwriter_set_indent_string($document, ' ');
-
xmlwriter_start_document($document, '1.0', 'UTF-8');
xmlwriter_start_element($document, 'report');
xmlwriter_start_attribute($document, 'title');
- xmlwriter_text($document, $this->report->title);
- xmlwriter_end_attribute($document);
- foreach ($this->report->sections as $section) {
- xmlwriter_start_element($document, 'section');
- xmlwriter_start_attribute($document, 'title');
- xmlwriter_text($document, $section->title);
+ if ($this->report->sections || $this->report->properties
+ || $this->report->title) {
+
+ xmlwriter_text($document, $this->report->title);
xmlwriter_end_attribute($document);
- foreach ($section->entries as $entry) {
- xmlwriter_start_element($document, 'entry');
+ foreach ($this->report->sections as $section) {
+ xmlwriter_start_element($document, 'section');
xmlwriter_start_attribute($document, 'title');
- xmlwriter_text($document, $entry->title);
+ xmlwriter_text($document, $section->title);
xmlwriter_end_attribute($document);
- xmlwriter_start_element($document, 'text');
- xmlwriter_text($document, $entry->text);
- xmlwriter_end_element($document);
+ foreach ($section->entries as $entry) {
+ xmlwriter_start_element($document, 'entry');
+
+ xmlwriter_start_attribute($document, 'title');
+ xmlwriter_text($document, $entry->title);
+ xmlwriter_end_attribute($document);
+
+ xmlwriter_start_element($document, 'text');
+ xmlwriter_text($document, $entry->text);
+ xmlwriter_end_element($document);
- xmlwriter_end_element($document);
+ xmlwriter_end_element($document);
+ }
+ xmlwriter_end_element($document); // section
}
- xmlwriter_end_element($document); // section
- }
- xmlwriter_start_element($document, 'data');
- xmlwriter_start_attribute($document, 'title');
- xmlwriter_text($document, "Properties");
- xmlwriter_end_attribute($document);
- foreach ($this->report->properties as $key => $value) {
- xmlwriter_start_element($document, 'entry');
+ if ($this->report->properties) {
- xmlwriter_start_element($document, 'key');
- xmlwriter_text($document, $key);
- xmlwriter_end_element($document);
+ xmlwriter_start_element($document, 'data');
+ xmlwriter_start_attribute($document, 'title');
+ xmlwriter_text($document, "Properties");
+ xmlwriter_end_attribute($document);
- xmlwriter_start_element($document, 'value');
- xmlwriter_text($document, $value);
- xmlwriter_end_element($document);
+ foreach ($this->report->properties as $key => $value) {
+ xmlwriter_start_element($document, 'entry');
- xmlwriter_end_element($document);
- }
- xmlwriter_end_element($document); // data
+ xmlwriter_start_element($document, 'key');
+ xmlwriter_text($document, $key);
+ xmlwriter_end_element($document);
+
+ xmlwriter_start_element($document, 'value');
+ xmlwriter_text($document, $value);
+ xmlwriter_end_element($document);
- xmlwriter_end_element($document); // report
+ xmlwriter_end_element($document);
+ }
+ xmlwriter_end_element($document); // data
+
+ xmlwriter_end_element($document);// report
+ }
+ }
xmlwriter_end_document($document);
return xmlwriter_output_memory($document);
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Oct 12, 05:23 (1 d, 8 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3065176
Default Alt Text
(12 KB)
Attached To
Mode
rKREPORT Keruald Report
Attached
Detach File
Event Timeline
Log In to Comment