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 {
$content .= '';
foreach(array_keys($first) 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($row as $col) {
$content .= '| '.print_r($col, true).' | ';
}
$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
';
}
echo $content;
}
}