/** * Return the root node for this connection * * @return Root */ public function root() { if ($this->root === null) { $this->root = Root::forConnection($this); } return $this->root; }
/** * Fetch result as tree * * @return Root * * @todo This is untested waste, not being used anywhere and ignores the query's order and base dn. * Evaluate whether it's reasonable to properly implement and test it. */ public function fetchTree() { $result = $this->fetchAll(); $sorted = array(); $quotedDn = preg_quote($this->ds->getDn(), '/'); foreach ($result as $key => &$item) { $new_key = LdapUtils::implodeDN(array_reverse(LdapUtils::explodeDN(preg_replace('/,' . $quotedDn . '$/', '', $key)))); $sorted[$new_key] = $key; } unset($groups); ksort($sorted); $tree = Root::forConnection($this->ds); $root_dn = $tree->getDN(); foreach ($sorted as $sort_key => &$key) { if ($key === $root_dn) { continue; } $tree->createChildByDN($key, $result[$key]); } return $tree; }