public function toTree(core_kernel_classes_Class $clazz, array $options = array())
    {
        $searchOptions = [];
        // show instances yes/no
        $instances = (isset($options['instances'])) ? $options['instances'] : true;
        // cut of the class and only display the children?
        $chunk = (isset($options['chunk'])) ? $options['chunk'] : false;
        // probably which subtrees should be opened
        $browse = (isset($options['browse'])) ? $options['browse'] : array();
        // limit of instances shown by subclass if no search label is given
        // if a search string is given, this is the total limit of results, independent of classes
        $limit = (isset($options['limit'])) ? $options['limit'] : 0;
        // offset for limit
        $offset = (isset($options['offset'])) ? $options['offset'] : 0;
        // A unique node URI to be returned from as a tree leaf.
        $uniqueNode = (isset($options['uniqueNode'])) ? $options['uniqueNode'] : null;

        if (isset($options['order']) && isset($options['orderdir'])) {
            $searchOptions['order'] = [$options['order'] => $options['orderdir']];
        }

        if ($uniqueNode !== null) {
            $instance = new \core_kernel_classes_Resource($uniqueNode);
            $results[] = TreeHelper::buildResourceNode($instance, $clazz);
            $returnValue = $results;
        } else {
            // Let's walk the tree with super walker! ~~~ p==[w]õ__
            array_walk($browse, function (&$item) {
                $item = \tao_helpers_Uri::decode($item);
            });
            $openNodes = TreeHelper::getNodesToOpen($browse, $clazz);

            if (!in_array($clazz->getUri(), $openNodes)) {
                $openNodes[] = $clazz->getUri();
            }

            $factory = new GenerisTreeFactory($instances, $openNodes, $limit, $offset, $browse, $this->getDefaultFilters(), $searchOptions);
            $tree = $factory->buildTree($clazz);
            $returnValue = $chunk
                ? (isset($tree['children']) ? $tree['children'] : array())
                : $tree;
        }
        return $returnValue;
    }