doc/lib: Use SimpleTree in the DocParser

refs #6630
This commit is contained in:
Eric Lippmann 2015-02-10 17:04:27 +01:00
parent 9f3b953165
commit c95838a33d

View File

@ -3,7 +3,8 @@
namespace Icinga\Module\Doc; namespace Icinga\Module\Doc;
use SplDoublyLinkedList; use SplStack;
use Icinga\Data\Tree\SimpleTree;
use Icinga\Exception\NotReadableError; use Icinga\Exception\NotReadableError;
use Icinga\Module\Doc\Exception\DocEmptyException; use Icinga\Module\Doc\Exception\DocEmptyException;
use Icinga\Module\Doc\Exception\DocException; use Icinga\Module\Doc\Exception\DocException;
@ -121,16 +122,15 @@ class DocParser
/** /**
* Get the documentation tree * Get the documentation tree
* *
* @return DocTree * @return SimpleTree
*/ */
public function getDocTree() public function getDocTree()
{ {
$tree = new DocTree(); $tree = new SimpleTree();
$stack = new SplDoublyLinkedList(); $stack = new SplStack();
foreach ($this->docIterator as $fileInfo) { foreach ($this->docIterator as $fileInfo) {
/* @var $file \SplFileInfo */ /** @type $fileInfo \SplFileInfo */
$file = $fileInfo->openFile(); $file = $fileInfo->openFile();
/* @var $file \SplFileObject */
$lastLine = null; $lastLine = null;
foreach ($file as $line) { foreach ($file as $line) {
$header = $this->extractHeader($line, $lastLine); $header = $this->extractHeader($line, $lastLine);
@ -142,7 +142,7 @@ class DocParser
if ($id === null) { if ($id === null) {
$path = array(); $path = array();
foreach ($stack as $section) { foreach ($stack as $section) {
/* @var $section Section */ /** @type $section DocSection */
$path[] = $section->getTitle(); $path[] = $section->getTitle();
} }
$path[] = $title; $path[] = $title;
@ -151,13 +151,20 @@ class DocParser
} else { } else {
$noFollow = false; $noFollow = false;
} }
if ($tree->getNode($id) !== null) {
$id = uniqid($id);
}
$section = new DocSection();
$section
->setId($id)
->setTitle($title)
->setLevel($level)
->setNoFollow($noFollow);
if ($stack->isEmpty()) { if ($stack->isEmpty()) {
$chapterId = $id; $section->setChapter($section);
$section = new Section($id, $title, $level, $noFollow, $chapterId); $tree->addChild($section);
$tree->addRoot($section);
} else { } else {
$chapterId = $stack->bottom()->getId(); $section->setChapter($stack->bottom());
$section = new Section($id, $title, $level, $noFollow, $chapterId);
$tree->addChild($section, $stack->top()); $tree->addChild($section, $stack->top());
} }
$stack->push($section); $stack->push($section);