00001 <?php
00002
00003
00007 class SimpleDumper {
00016 function describeValue($value) {
00017 $type = $this->getType($value);
00018 switch ($type) {
00019 case "Null":
00020 return "NULL";
00021
00022 case "Bool":
00023 return "Boolean: ". ($value ? "true" : "false");
00024
00025 case "Array":
00026 return "Array: ". count($value) ." items";
00027
00028 case "Object":
00029 return "Object: of ". get_class($value);
00030
00031 case "String":
00032 return "String: ". $this->clipString($value, 200);
00033
00034 default:
00035 return "$type: $value";
00036 }
00037 }
00038
00045 function getType($value) {
00046 if (!isset($value)) {
00047 return "Null";
00048 }
00049 $functions = array('bool', 'string', 'integer', 'float', 'array', 'resource', 'object');
00050 foreach ($functions as $function) {
00051 $function_name = 'is_' . $function;
00052 if ($function_name($value)) {
00053 return ucfirst($function);
00054 }
00055 }
00056 return "Unknown";
00057 }
00058
00067 function clipString($value, $size, $position = 0) {
00068 $length = strlen($value);
00069 if ($length <= $size) {
00070 return $value;
00071 }
00072 $position = min($position, $length);
00073 $start = ($size / 2 > $position ? 0 : $position - $size / 2);
00074 if ($start + $size > $length) {
00075 $start = $length - $size;
00076 }
00077 $value = substr($value, $start, $size);
00078 return ($start > 0 ? "..." : "") . $value . ($start + $size < $length ? "..." : "");
00079 }
00080 }