From: Alan Knowles Date: Wed, 28 Apr 2021 05:13:02 +0000 (+0800) Subject: Fix #6692 - fix docs X-Git-Url: http://git.roojs.org/?p=PHP_CodeDoc;a=commitdiff_plain;h=8410be6bb2e267611275f039c898391b275d2d3d Fix #6692 - fix docs --- diff --git a/CodeDoc/Parser.php b/CodeDoc/Parser.php index 098aa9c..e8fc5ee 100644 --- a/CodeDoc/Parser.php +++ b/CodeDoc/Parser.php @@ -140,7 +140,9 @@ class PHP_CodeDoc_Parser { //echo "READ: $filename/$file\n"; if (is_file($filename."/".$file)) { - if (!ereg("\.(inc|php|class)$",$file)) continue; + if (!preg_match("/\.(inc|php|class)$/",$file)) { + continue; + } $this->files[$filename][] = $file; } elseif (is_dir($filename."/".$file)) { @@ -312,7 +314,7 @@ class PHP_CodeDoc_Parser { $this->last_comment_block = $v[1]; - PHP_CodeDoc_Parser_Docbook::read($this->last_comment_block,$inclass); + PHP_CodeDoc_Parser_Docbook::read($this, $this->last_comment_block,$inclass); break; default: //echo "{$this->pos}:" . diff --git a/CodeDoc/Parser/Docbook.php b/CodeDoc/Parser/Docbook.php new file mode 100644 index 0000000..d54510f --- /dev/null +++ b/CodeDoc/Parser/Docbook.php @@ -0,0 +1,170 @@ + | +// +----------------------------------------------------------------------+ +// +/** +* Docbook data container (for pages and sections) +* +* @package PHP_CodeDoc +* @access public +* @author Alan Knowles +* +*/ + + +class PHP_CodeDoc_Parser_Docbook { + + + + static function read(PHP_CodeDoc_Parser $thiz, $comment,$inclass) { // called statically as part of the parser (and $this will actually be Parser) + //class name should be next! + $thiz->debug(__METHOD__, substr($comment, 0, 30)); + // is docbook generation enabled? + $options = PHP_CodeDoc::$options; + if (!@$options['makeDocbook']) return; + + + // all docbook comments should start /* + if (substr(trim($comment),0,2) != "/*") { + return; + } + + + $parts = explode("_",$thiz->active_package->name); + $pfile = $parts[count($parts) -1]; + //* we only read sections when the filename matches the package name + //if (!preg_match("/\/{$pfile}.php$/",$this->rfilename)) { + // return; + //} + + if (!$inclass) { + // only understand page breaks when comments in classes + /* valid comment is /**(*****) some stuff without a start **** / */ + echo "LOOKING FOR DOC BOOK \n"; + $args = array(); + if (preg_match('/^\s*\*\s*@/mi',$comment,$args)) { + $docbook = &$thiz->active_package->docbook; + $docbook->addPage($thiz->active_package->name); + $docbook->addSection('Introduction'); + + $thiz->active_package->docbookBase = $docbook->parse($comment); + + } + return; + } + /* otherwise we are in a header area?? */ + + } + + function parse($comment) { + $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 "page:": + $page = preg_replace("/\s*page:\s*/i","",$line); + PHP_CodeDoc_Parser_Docbook::addPara($buffer); + $buffer =""; + PHP_CodeDoc_Parser_Docbook::addPage($page); + break; + case "section:": + $section = preg_replace("/\s*section:\s*/i","",$line); + PHP_CodeDoc_Parser_Docbook::addPara($buffer); + $buffer =""; + PHP_CodeDoc_Parser_Docbook::addSection($section); + break; + case "pagesummary:": + $summary = preg_replace("/\s*pagesummary:\s*/i","",$line); + PHP_CodeDoc_Parser_Docbook::addPara($buffer); + $buffer =""; + PHP_CodeDoc_Parser_Docbook::addPageSummary($summary); + break; + + case "packagesection:": + + PHP_CodeDoc_Parser_Docbook::addPara($buffer); + $buffer =""; + $ps = preg_replace("/\s*packagesection:\s*/i","",$line); + $this->active_package->docbookBase = trim($ps); + break; + + case "list:": + PHP_CodeDoc_Parser_Docbook::addPara($buffer); + $buffer =""; + break; + case "endlist:": + PHP_CodeDoc_Parser_Docbook::addList($buffer); + $buffer =""; + break; + default: + if (trim($line) == "") { + if (trim($buffer) == "") { + break; + } + PHP_CodeDoc_Parser_Docbook::addPara($buffer); + $buffer= ""; + break; + } + $buffer .= $line . "\n"; + + } + + } + PHP_CodeDoc_Parser_Docbook::addPara($buffer); + //print_r($this->active_package->docbook); + + + } + + function addPara($lines) { + if ($lines == "") { + return; + } + $this->active_package->docbook->Operations = & $this->classes[$this->_active_class]->Operations; + $this->active_package->docbook->iOperations = & $this->classes[$this->_active_class]->iOperations; + } + + + + + + + /* ---------- method notes ------------- */ + function parseMethodComment(&$method) { + // add a new section for it! + /* if ($method->class != $this->_active_package..... */ + + if ($method->name{0} == "_") return; + $docbook->addSection($method->class . "::". $method->name); + $this->_activeSection->method = &$method; + } + + + + + +} + +?>