<?php

function dumpTree($tree, $self, $showLinks = false, $level = 0)
{
    $html = '';
    foreach ($tree as $name => $node) {
        $html .= '<li>';

        if ($showLinks || $name === 'ConfigObject') {
            $link = $self->qlink(
                $name,
                'director/inspect/type',
                array('endpoint' => $self->endpoint, 'name' => $name),
                array('class' => $node->abstract ? 'abstract' : 'object')
            );
        } else {
            $link = sprintf(
                '<a class="%s" href="#">%s</a>',
                $node->abstract ? 'abstract' : 'object',
                $name
            );
        }
        if (property_exists($node, 'children')) {
            $html .= '<span class="handle"> </span>';
            $html .= $link;
            $html .= '<ul>' . dumpTree(
                $node->children,
                $self,
                $showLinks || $name === 'ConfigObject',
                $level + 1
            ) . '</ul>';
        } else {
            $html .= $link;
        }
        $html .= '</li>';
    }

    return $html;
}

?>
<div class="controls">
<?= $this->tabs ?>
<h1><?= $this->escape($this->title) ?></h1>
</div>

<div class="content">
<ul class="tree" style="margin-left: 2em;" data-base-target="_next">
<?= dumpTree($this->types, $this) ?>
</ul>
</div>
