CodeDoc/Data/Docbook.php
authorAlan Knowles <alan@roojs.com>
Thu, 13 Oct 2016 08:02:35 +0000 (16:02 +0800)
committerAlan Knowles <alan@roojs.com>
Thu, 13 Oct 2016 08:02:35 +0000 (16:02 +0800)
CodeDoc/Data/Docbook.php [new file with mode: 0644]

diff --git a/CodeDoc/Data/Docbook.php b/CodeDoc/Data/Docbook.php
new file mode 100644 (file)
index 0000000..504907d
--- /dev/null
@@ -0,0 +1,258 @@
+<?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_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 "<para>\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 "</para>\n";
+        }
+        
+    }
+    
+    function _outputList($items) {
+        echo "<itemizedlist>\n";
+        foreach($items as $item) {
+            if (trim($item) == "") {    
+                continue;
+            }
+            echo "  <listitem>\n    ". htmlspecialchars($item) ."\n  </listitem>\n";
+        }
+        echo "<itemizedlist>\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