array('funcname' => DATA))
// so take the first element of the 'result' array
$data = reset($data['result']);
$first = reset($data);
$single = ! is_array($first);
$content = '
';
if($single) {
$content .= "| Field | Value |
";
} else {
$columns = array_keys($first);
$content .= '';
foreach($columns as $k) {
$content .= "| $k | ";
}
$content .= '
';
}
$content .= '';
if($single) {
foreach($data as $k => $v) {
$content .= "| $k | ".print_r($v, true)." |
";
}
} else {
foreach($data as $row) {
$content .= '';
foreach($columns as $c) {
$v = print_r(isset($row[$c]) ? $row[$c] : '', true);
$limit = 50;
if(strlen($v) > $limit) {
$v = substr($v, 0, $limit).' [...]';
}
$content .= "| $v | ";
}
$content .= '
';
}
}
$content .= '
';
return $content;
}
private function error($data) {
$code = $data['error']['code'];
$name = $data['error']['name'];
$msg = $data['error']['reason'];
return 'An error occured
'.
"[$code] $name
".
"$msg
";
}
private function failure($data) {
$code = $data['failure']['code'];
$name = $data['failure']['reason'];
return 'A failure occured
'.
"[$code] $name
";
}
public function render($data)
{
$type = key($data);
if (method_exists($this, $type)) {
$content = call_user_func_array(array($this, $type), array($data));
} else {
$content = 'Unable to render this
';
}
$html = file_get_contents('template.html');
$context = array(
'title' => 'BSR - WebService',
'content' => $content
);
foreach($context as $k => $v) {
$html = str_replace("{{ $k }}", $v, $html);
}
echo $html;
}
}