public static function go($inp, $key = 'root', $exp_lvls = 1000, $st = true) { $inject = ''; if (self::$initial) { $inject = self::$css . self::$js; self::$initial = false; } $buf = ''; $buf .= $st ? "{$inject}<pre class=\"dump_r\"><ul>" : ''; $t = self::checkType($inp); $disp = htmlspecialchars($t->disp); $len = !is_null($t->length) ? "<div class=\"len\">{$t->length}</div>" : ''; $sub = !is_null($t->subtype) && !is_bool($inp) ? "<div class=\"sub\">{$t->subtype}</div>" : ''; $excol = is_array($t->children) && !empty($t->children) ? '<div class="excol"></div>' : ''; $exp_state = $excol ? $exp_lvls > 0 ? ' expanded' : ' collapsed' : ''; $empty = empty($inp) ? ' empty' : ''; $numeric = is_numeric($inp) ? ' numeric' : ''; $t->subtype = $t->subtype ? ' ' . $t->subtype : $t->subtype; $buf .= "<li class=\"{$t->type}{$t->subtype}{$numeric}{$empty}{$exp_state}\">{$excol}<div class=\"lbl\"><div class=\"key\">{$key}</div><div class=\"val\">{$disp}</div><div class=\"typ\">({$t->type})</div>{$sub}{$len}</div>"; if ($t->children) { $buf .= '<ul>'; foreach ($t->children as $k => $v) { if ($v === $inp) { $v = self::$self; } $buf .= self::go($v, $k, $exp_lvls - 1, false); } $buf .= '</ul>'; } $buf .= '</li>'; $buf .= $st ? '</ul></pre>' : ''; return $buf; }
public static function renderHTML($struct, $key = 'root', $vis = 2, $expand = 1000, $st = true, $bktrc = null) { // track max key width (8px/char) self::$keyWidth = max(self::$keyWidth, strlen($key) * self::$chrWidth); $inject = ''; if (self::$initial) { $inject = self::$css . self::$js; self::$initial = false; } $buf = ''; if ($st) { $dump_id = 'dump-' . rand(100, 999); $where = $bktrc !== null ? "<div class=\"file-line\">{$bktrc->file} (line {$bktrc->line})</div>" : ''; $buf .= "{$inject}<pre class=\"dump_r\" id=\"{$dump_id}\">{$where}<ul>"; } $s =& $struct; $disp = htmlspecialchars($s->disp); // add jumps to referenced objects if (!empty($s->hash)) { $disp = "<a name=\"{$s->hash}\">{$disp}</a>"; } else { if ($s->type == 'ref') { $disp = "<a href=\"#{$s->ref->hash}\">{$disp}</a>"; } } $len = !is_null($s->length) ? "<div class=\"len\">{$s->length}</div>" : ''; $sub = !is_null($s->subtype) ? "<div class=\"sub\">{$s->subtype}</div>" : ''; $excol = !empty($s->children) ? '<div class="excol"></div>' : ''; $exp_state = $excol ? $expand > 0 ? ' expanded' : ' collapsed' : ''; $empty = $s->empty ? ' empty' : ''; $numeric = $s->numeric ? ' numeric' : ''; $subtype = $s->subtype ? " {$s->subtype}" : ''; $privprot = $vis === 1 ? ' protected' : ($vis === 0 ? ' private' : ''); $depthlim = $s->depthlim ? ' depthlim' : ''; $classes = $s->classes ? ' ' . implode(' ', $s->classes) : ''; $buf .= "<li class=\"{$s->type}{$subtype}{$numeric}{$empty}{$privprot}{$classes}{$depthlim}{$exp_state}\">{$excol}<div class=\"lbl\"><div class=\"key\">{$key}</div><div class=\"val\">{$disp}</div><div class=\"typ\">({$s->type})</div>{$sub}{$len}</div>"; if ($s->children) { $buf .= '<ul>'; foreach ($s->children as $k => $s2) { $buf .= self::renderHTML($s2, $k, $s->childvis[$k], $expand - 1, false); } $buf .= '</ul>'; } $buf .= '</li>'; if ($st) { $buf .= "</ul><style>#{$dump_id} .key {min-width: " . self::$keyWidth . 'px;}</style></pre>'; self::$keyWidth = 0; // reset } return $buf; }