|
|
|
|
@ -13,12 +13,13 @@ class Html extends Formatter {
|
|
|
|
|
private function result($data) {
|
|
|
|
|
// the format is array('result' => array('funcname' => DATA))
|
|
|
|
|
// so take the first element of the 'result' array
|
|
|
|
|
$func = key($data['result']);
|
|
|
|
|
$data = reset($data['result']);
|
|
|
|
|
|
|
|
|
|
$first = reset($data);
|
|
|
|
|
$single = ! is_array($first);
|
|
|
|
|
|
|
|
|
|
$content = '<table class="table table-striped table-hover"><thead>';
|
|
|
|
|
$content = '<table class="table table-striped table-hover table-condensed table-responsive"><thead>';
|
|
|
|
|
if($single) {
|
|
|
|
|
$content .= "<tr><th>Field</th><th>Value</th></tr>";
|
|
|
|
|
} else {
|
|
|
|
|
@ -52,7 +53,11 @@ class Html extends Formatter {
|
|
|
|
|
}
|
|
|
|
|
$content .= '</tbody></table>';
|
|
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
|
return array(
|
|
|
|
|
'title' => $func,
|
|
|
|
|
'content' => $content,
|
|
|
|
|
'status' => 'success',
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function error($data) {
|
|
|
|
|
@ -60,17 +65,22 @@ class Html extends Formatter {
|
|
|
|
|
$name = $data['error']['name'];
|
|
|
|
|
$msg = $data['error']['reason'];
|
|
|
|
|
|
|
|
|
|
return '<h1>An error occured</h1>'.
|
|
|
|
|
"<h2>[$code] $name</h2>".
|
|
|
|
|
"<p>$msg</p>";
|
|
|
|
|
return array(
|
|
|
|
|
'title' => 'Error',
|
|
|
|
|
'content' => "<h2>[$code] $name : $msg</h2>",
|
|
|
|
|
'status' => 'warning',
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function failure($data) {
|
|
|
|
|
$code = $data['failure']['code'];
|
|
|
|
|
$name = $data['failure']['reason'];
|
|
|
|
|
|
|
|
|
|
return '<h1>A failure occured</h1>'.
|
|
|
|
|
"<h2>[$code] $name</h2>";
|
|
|
|
|
return array(
|
|
|
|
|
'title' => 'Failure',
|
|
|
|
|
'content' => "<h2>[$code] $name</h2>",
|
|
|
|
|
'status' => 'danger',
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function render($data)
|
|
|
|
|
@ -78,18 +88,17 @@ class Html extends Formatter {
|
|
|
|
|
$type = key($data);
|
|
|
|
|
|
|
|
|
|
if (method_exists($this, $type)) {
|
|
|
|
|
$content = call_user_func_array(array($this, $type), array($data));
|
|
|
|
|
$context = call_user_func_array(array($this, $type), array($data));
|
|
|
|
|
} else {
|
|
|
|
|
$content = '<h1>Unable to render this</h1>';
|
|
|
|
|
$context = array(
|
|
|
|
|
'title' => 'Formatter error',
|
|
|
|
|
'content' => '<h1>Unable to render this</h1>',
|
|
|
|
|
'status' => 'info',
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$html = file_get_contents('template.html');
|
|
|
|
|
|
|
|
|
|
$context = array(
|
|
|
|
|
'title' => 'BSR - WebService',
|
|
|
|
|
'content' => $content
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
foreach($context as $k => $v) {
|
|
|
|
|
$html = str_replace("{{ $k }}", $v, $html);
|
|
|
|
|
}
|
|
|
|
|
|