コード例 #1
0
 /**
  * Get the documentation tree
  *
  * @return SimpleTree
  */
 public function getDocTree()
 {
     $tree = new SimpleTree();
     foreach ($this->docIterator as $fileInfo) {
         /** @var $fileInfo \SplFileInfo */
         $file = $fileInfo->openFile();
         $lastLine = null;
         $stack = new SplStack();
         $cachingIterator = new CachingIterator($file, CachingIterator::TOSTRING_USE_CURRENT);
         for ($cachingIterator->rewind(); $line = $cachingIterator->valid(); $cachingIterator->next()) {
             $fileIterator = $cachingIterator->getInnerIterator();
             $line = $cachingIterator->current();
             $header = $this->extractHeader($line, $fileIterator->valid() ? $fileIterator->current() : null);
             if ($header !== null) {
                 list($title, $id, $level, $headerStyle) = $header;
                 while (!$stack->isEmpty() && $stack->top()->getLevel() >= $level) {
                     $stack->pop();
                 }
                 if ($id === null) {
                     $path = array();
                     foreach ($stack as $section) {
                         /** @var $section DocSection */
                         $path[] = $section->getTitle();
                     }
                     $path[] = $title;
                     $id = implode('-', $path);
                     $noFollow = true;
                 } else {
                     $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()) {
                     $section->setChapter($section);
                     $tree->addChild($section);
                 } else {
                     $section->setChapter($stack->bottom());
                     $tree->addChild($section, $stack->top());
                 }
                 $stack->push($section);
                 if ($headerStyle === static::HEADER_SETEXT) {
                     $cachingIterator->next();
                     continue;
                 }
             } else {
                 if ($stack->isEmpty()) {
                     $title = ucfirst($file->getBasename('.' . pathinfo($file->getFilename(), PATHINFO_EXTENSION)));
                     $id = $title;
                     if ($tree->getNode($id) !== null) {
                         $id = uniqid($id);
                     }
                     $section = new DocSection();
                     $section->setId($id)->setTitle($title)->setLevel(1)->setNoFollow(true);
                     $section->setChapter($section);
                     $tree->addChild($section);
                     $stack->push($section);
                 }
                 $stack->top()->appendContent($line);
             }
         }
     }
     return $tree;
 }
コード例 #2
0
ファイル: DocParser.php プロジェクト: hsanjuan/icingaweb2
 /**
  * Get the documentation tree
  *
  * @return SimpleTree
  */
 public function getDocTree()
 {
     $tree = new SimpleTree();
     $stack = new SplStack();
     foreach ($this->docIterator as $fileInfo) {
         /** @var $fileInfo \SplFileInfo */
         $file = $fileInfo->openFile();
         $lastLine = null;
         foreach ($file as $line) {
             $header = $this->extractHeader($line, $lastLine);
             if ($header !== null) {
                 list($title, $id, $level) = $header;
                 while (!$stack->isEmpty() && $stack->top()->getLevel() >= $level) {
                     $stack->pop();
                 }
                 if ($id === null) {
                     $path = array();
                     foreach ($stack as $section) {
                         /** @var $section DocSection */
                         $path[] = $section->getTitle();
                     }
                     $path[] = $title;
                     $id = implode('-', $path);
                     $noFollow = true;
                 } else {
                     $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()) {
                     $section->setChapter($section);
                     $tree->addChild($section);
                 } else {
                     $section->setChapter($stack->bottom());
                     $tree->addChild($section, $stack->top());
                 }
                 $stack->push($section);
             } else {
                 if ($stack->isEmpty()) {
                     throw new LogicException('Heading required');
                 }
                 $stack->top()->appendContent($line);
             }
             // Save last line for setext-style headers
             $lastLine = $line;
         }
     }
     return $tree;
 }