function StatisticsProBaseTestCase::get_dump in Statistics Pro 6
Same name and namespace in other branches
- 6.2 tests/statspro.test \StatisticsProBaseTestCase::get_dump()
File
- tests/
statspro.test, line 268 - Functionality tests for Statistics Pro.
Class
- StatisticsProBaseTestCase
- Base class for Statistics Pro tests.
Code
function get_dump($value, $level = 0) {
if ($level == -1) {
$trans[' '] = '∴';
$trans["\t"] = '⇒';
$trans["\n"] = '¶;';
$trans["\r"] = '⇐';
$trans["\0"] = '⊕';
return strtr(htmlspecialchars($value), $trans);
}
$output = '';
if ($level == 0) {
$output .= '<pre>';
}
$type = gettype($value);
$output .= $type;
if ($type == 'string') {
$output .= '(' . mb_strlen($value) . ')';
$value = dump($value, -1);
}
elseif ($type == 'boolean') {
$value = $value ? 'true' : 'false';
}
elseif ($type == 'object') {
$props = get_class_vars(get_class($value));
$output .= '(' . count($props) . ') <u>' . get_class($value) . '</u>';
foreach ($props as $key => $val) {
$output .= "\n" . str_repeat("\t", $level + 1) . $key . ' => ';
$output .= dump($value->{$key}, $level + 1);
}
$value = '';
}
elseif ($type == 'array') {
$output .= '(' . count($value) . ')';
foreach ($value as $key => $val) {
$output .= "\n" . str_repeat("\t", $level + 1) . dump($key, -1) . ' => ';
$output .= dump($val, $level + 1);
}
$value = '';
}
$output .= " <b>{$value}</b>";
if ($level == 0) {
$output .= '</pre>';
}
return $output;
}