Fix #6692 - fix docs master
authorAlan Knowles <alan@roojs.com>
Wed, 28 Apr 2021 05:13:02 +0000 (13:13 +0800)
committerAlan Knowles <alan@roojs.com>
Wed, 28 Apr 2021 05:13:02 +0000 (13:13 +0800)
CodeDoc/Parser.php
CodeDoc/Parser/Docbook.php [new file with mode: 0644]

index 098aa9c..e8fc5ee 100644 (file)
@@ -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 (file)
index 0000000..d54510f
--- /dev/null
@@ -0,0 +1,170 @@
+<?php
+
+// +----------------------------------------------------------------------+
+// | PHP Version 4                                                        |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997-2002 The PHP Group                                |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.02 of the PHP license,      |
+// | that is bundled with this package in the file LICENSE, and is        |
+// | available at through the world-wide-web at                           |
+// | http://www.php.net/license/2_02.txt.                                 |
+// | If you did not receive a copy of the PHP license and are unable to   |
+// | obtain it through the world-wide-web, please send a note to          |
+// | license@php.net so we can mail you a copy immediately.               |
+// +----------------------------------------------------------------------+
+// | Authors: Alan Knowles <alan@akbkhome.com>                      |
+// +----------------------------------------------------------------------+
+//
+/**
+*   Docbook data container (for pages and sections)
+*
+*   @package  PHP_CodeDoc
+*   @access   public
+*   @author   Alan Knowles <alan@akbkhome.com>
+*
+*/
+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;
+    }
+    
+    
+    
+        
+     
+}
+
+?>