Fix #6692 - fix docs
[PHP_CodeDoc] / CodeDoc / Parser / Docbook.php
1 <?php
2
3 // +----------------------------------------------------------------------+
4 // | PHP Version 4                                                        |
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997-2002 The PHP Group                                |
7 // +----------------------------------------------------------------------+
8 // | This source file is subject to version 2.02 of the PHP license,      |
9 // | that is bundled with this package in the file LICENSE, and is        |
10 // | available at through the world-wide-web at                           |
11 // | http://www.php.net/license/2_02.txt.                                 |
12 // | If you did not receive a copy of the PHP license and are unable to   |
13 // | obtain it through the world-wide-web, please send a note to          |
14 // | license@php.net so we can mail you a copy immediately.               |
15 // +----------------------------------------------------------------------+
16 // | Authors: Alan Knowles <alan@akbkhome.com>                      |
17 // +----------------------------------------------------------------------+
18 //
19 /**
20 *   Docbook data container (for pages and sections)
21 *
22 *   @package  PHP_CodeDoc
23 *   @access   public
24 *   @author   Alan Knowles <alan@akbkhome.com>
25 *
26 */
27  
28  
29 class PHP_CodeDoc_Parser_Docbook  {
30     
31     
32     
33     static function read(PHP_CodeDoc_Parser $thiz, $comment,$inclass) { // called statically as part of the parser (and $this will actually be Parser)
34         //class name should be next!
35         $thiz->debug(__METHOD__, substr($comment, 0, 30));
36         // is docbook generation enabled?
37         $options = PHP_CodeDoc::$options;
38         if (!@$options['makeDocbook']) return;
39         
40         
41         // all docbook comments should start  /*
42         if (substr(trim($comment),0,2) != "/*") {
43             return;
44         }
45         
46         
47         $parts = explode("_",$thiz->active_package->name);
48         $pfile = $parts[count($parts) -1];
49          //* we only read sections when the filename matches the package name
50         //if (!preg_match("/\/{$pfile}.php$/",$this->rfilename)) {
51         //    return;
52         //}
53         
54         if (!$inclass) {
55             // only understand page breaks when comments in classes 
56             /* valid comment is /**(*****) some stuff without a start **** /  */
57             echo "LOOKING FOR DOC BOOK \n";
58             $args = array();
59             if (preg_match('/^\s*\*\s*@/mi',$comment,$args)) {
60                 $docbook = &$thiz->active_package->docbook;
61                 $docbook->addPage($thiz->active_package->name);
62                 $docbook->addSection('Introduction');
63                  
64                 $thiz->active_package->docbookBase = $docbook->parse($comment);
65                  
66             }
67             return;
68         }
69         /* otherwise we are in a header area?? */
70          
71     }
72     
73     function parse($comment) {
74         $lines = explode("\n",$comment);
75         $buffer = "";
76         foreach ($lines as $line) {
77             // get rid of trailing *
78             $line = preg_replace("/^\s*\/*[\*]+\/*/","",$line);
79             
80             //$line = preg_replace("/^\s*\*/","",$line);
81             $bits = explode(' ', strtolower(trim($line)));
82             //echo "CASE {$bits[0]}\n";
83             switch ($bits[0]) {
84                 case "@docbook":
85                     break;
86                 case "page:":
87                     $page = preg_replace("/\s*page:\s*/i","",$line);
88                     PHP_CodeDoc_Parser_Docbook::addPara($buffer);
89                     $buffer ="";
90                     PHP_CodeDoc_Parser_Docbook::addPage($page);
91                     break;
92                 case "section:":
93                     $section = preg_replace("/\s*section:\s*/i","",$line);
94                     PHP_CodeDoc_Parser_Docbook::addPara($buffer);
95                     $buffer ="";
96                     PHP_CodeDoc_Parser_Docbook::addSection($section);
97                     break;
98                 case "pagesummary:":
99                     $summary = preg_replace("/\s*pagesummary:\s*/i","",$line);
100                     PHP_CodeDoc_Parser_Docbook::addPara($buffer);
101                     $buffer ="";
102                     PHP_CodeDoc_Parser_Docbook::addPageSummary($summary);
103                     break;
104                      
105                 case "packagesection:":
106                     
107                     PHP_CodeDoc_Parser_Docbook::addPara($buffer);
108                     $buffer ="";
109                     $ps = preg_replace("/\s*packagesection:\s*/i","",$line);
110                     $this->active_package->docbookBase = trim($ps);
111                     break;
112                         
113                 case "list:":
114                     PHP_CodeDoc_Parser_Docbook::addPara($buffer);
115                     $buffer ="";
116                     break;
117                 case "endlist:":
118                     PHP_CodeDoc_Parser_Docbook::addList($buffer);
119                      $buffer ="";
120                     break;
121                 default:
122                     if (trim($line) == "") {
123                         if (trim($buffer) == "") {
124                             break;
125                         }
126                         PHP_CodeDoc_Parser_Docbook::addPara($buffer);
127                         $buffer= "";
128                         break;
129                     }
130                     $buffer .= $line . "\n";
131                     
132             }
133             
134         }
135        PHP_CodeDoc_Parser_Docbook::addPara($buffer);
136        //print_r($this->active_package->docbook);
137       
138        
139     }
140     
141     function addPara($lines) {
142         if ($lines == "") {
143             return;
144         }
145         $this->active_package->docbook->Operations = & $this->classes[$this->_active_class]->Operations;
146         $this->active_package->docbook->iOperations = & $this->classes[$this->_active_class]->iOperations;
147     }
148     
149     
150     
151      
152     
153      
154     /* ---------- method notes ------------- */
155     function parseMethodComment(&$method) {
156         // add a new section for it!
157         /* if ($method->class !=  $this->_active_package..... */
158         
159         if ($method->name{0} == "_") return;
160         $docbook->addSection($method->class . "::". $method->name);
161         $this->_activeSection->method = &$method;
162     }
163     
164     
165     
166         
167      
168 }
169
170 ?>