From 57787a04a33afedccbf6523608a32327b2f9cbd6 Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Thu, 13 Oct 2016 16:02:35 +0800 Subject: [PATCH] CodeDoc/Data/Docbook.php --- CodeDoc/Data/Docbook.php | 258 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 258 insertions(+) create mode 100644 CodeDoc/Data/Docbook.php diff --git a/CodeDoc/Data/Docbook.php b/CodeDoc/Data/Docbook.php new file mode 100644 index 0000000..504907d --- /dev/null +++ b/CodeDoc/Data/Docbook.php @@ -0,0 +1,258 @@ + | +// +----------------------------------------------------------------------+ +// +/** +* Docbook data container (for pages and sections) +* +* @package PHP_CodeDoc +* @access public +* @author Alan Knowles +* +*/ +class PHP_CodeDoc_Data_Docbook { + var $pages = array(); // + var $name; // name of parameter + var $title; // title + var $tagname; // name that appears in url + var $sections = array(); // array of sections; + var $paras = array(); // array of paragraphs; + var $Operations = array(); // book methods + var $iOperations = array(); // book iherited Methods + + var $_activeSection; // link to current section + var $_activePage; // link to active page. + + function outputDocbook() { + // should read an array from para's and output the correct docbook/xml tags + + foreach ($this->paras as $para) { + echo "\n"; + if (is_array($para)) { + switch ($para[0]) { + case "LIST": + $this->_outputList($para[1]); + break; + default: + echo "UNKNOWN PARA"; + } + + } else { + echo htmlspecialchars($para) . "\n"; + } + echo "\n"; + } + + } + + function _outputList($items) { + echo "\n"; + foreach($items as $item) { + if (trim($item) == "") { + continue; + } + echo " \n ". htmlspecialchars($item) ."\n \n"; + } + echo "\n"; + } + + function outputSummary() { + + echo $this->pages['INDEX']->paras[0]; + unset($this->pages['INDEX']); + } + + + + function parse($comment) { + $ret = ""; + $flag_inlist = FALSE; + $lines = explode("\n",$comment); + $buffer = ""; + foreach ($lines as $line) { + // get rid of trailing * + $line = preg_replace("/^\s*\/*[\*]+\/*/","",$line); + + //$line = preg_replace("/^\s*\*/","",$line); + $bits = explode(' ', strtolower(trim($line))); + //echo "CASE {$bits[0]}\n"; + switch ($bits[0]) { + case "@docbook": + break; + case "@docbook_page": + $page = preg_replace("/\s*\@docbook_page\s*/i","",$line); + $this->addPara($buffer); + $buffer =""; + $this->addPage($page); + break; + case "@docbook_section": + $section = preg_replace("/\s*\@docbook_section\s*/i","",$line); + $this->addPara($buffer); + $buffer =""; + $this->addSection($section); + break; + case "@docbook_page_summary": + $summary = preg_replace("/\s*\@docbook_page_summary\s*/i","",$line); + $this->addPara($buffer); + $buffer =""; + $this->addPageSummary($summary); + break; + + case "@docbook_package_section": + + $this->addPara($buffer); + $buffer =""; + $ps = preg_replace("/\s*\@docbook_package_section\s*/i","",$line); + $ret = trim($ps); + break; + case "@docbook_package_title": + $this->addPara($buffer); + $buffer =""; + $ps = preg_replace("/\s*\@docbook_package_title\s*/i","",$line); + $this->title = trim($ps); + break; + case "@docbook_list": + $this->addPara($buffer); + $flag_inlist = TRUE; + $buffer =""; + break; + /* Standard phpdoc stuff */ + case "@param": + case "@return": + case "@access": + case "@author": + case "@copyright": + case "@version": + case "@see": + case "@link": + case "@since": + case "@deprecated": + case "@deprec": + case "@magic": + case "@todo": + case "@exception": + case "@throws": + case "@var": + case "@package": + case "@subpackage": + break; + + default: + if (trim($line) == "") { + if (trim($buffer) == "") { + break; + } + if ($flag_inlist) { + $this->addList($buffer); + $flag_inlist= FALSE; + } else { + $this->addPara($buffer); + } + $buffer= ""; + break; + } + $buffer .= $line . "\n"; + + } + + } + $this->addPara($buffer); + return $ret; + } + + + function &addPage($page) { + $page = trim($page); + + $this->pages[$page] = new PHP_CodeDoc_Data_Docbook; + /* create links .. */ + $this->_activeSection = &$this->pages[$page]; + $this->_activePage = &$this->pages[$page]; + $this->_activePage->type = 'Page'; + unset($this->_activePage->pages); + /* set stuff */ + $this->_activePage->name = $page; + $this->_activePage->title = $page; + $this->_activePage->tagname = preg_replace("/[^a-z0-9]/i", "-",trim($page)); + return $this->pages[$page]; + } + function addPageSummary($summary) { + $this->_activePage->summary = $summary; + } + + function addSection($section) { + if (!$this->_activePage->type == 'Page') { + $this->addPage($section); + } + $section = trim($section); + $this->_activePage->sections[$section] = new PHP_CodeDoc_Data_Docbook; + $this->_activeSection = &$this->_activePage->sections[$section]; + $this->_activeSection->name = $section; + $this->_activeSection->title = $section; + unset($this->_activeSection->pages); + unset($this->_activeSection->sections); + } + function addList($lines) { + $this->_activeSection->paras[] = array("LIST", explode("\n",$lines)); + } + function addPara($lines) { + if ($lines == "") { + return; + } + $this->_activeSection->paras[] = $lines; + + } + function setMethod(&$method) { + $method->mergePhpDoc(); + $this->_activeSection->method = &$method; + } + function mergeMethods() { + + foreach(array_keys($this->Operations) as $id) { + $method = &$this->Operations[$id]; + if ($method->name{0} == "_") { + continue; + } + + $this->addSection($method->class . "::". $method->name); + + $this->setMethod($method); + $this->parse($method->description->original); + } + foreach(array_keys($this->iOperations) as $id) { + $this-> + $method = &$this->iOperations[$id]; + if ($this->name{0} == "_") { + continue; + } + + $this->addSection($method->class . "::". $method->name); + $this->parse($method->description->original); + $this->setMethod($method); + } + } + + function longToHtml() + { + + + + + } + +} + \ No newline at end of file -- 2.39.2