File: phpdoc.class

package info (click to toggle)
myphpmoney 1.3RC3-13
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,160 kB
  • ctags: 884
  • sloc: php: 18,081; pascal: 2,106; sh: 327; xml: 239; makefile: 137; sql: 130
file content (487 lines) | stat: -rw-r--r-- 14,459 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
<?php
/**
 * $Id: phpdoc.class,v 1.10 2003/03/26 08:31:37 courou Exp $
 * Contact author at:
 *
 * Author     : courou&#64;users.sourceforge.net
 * Website    : http://allreponse.ath.cx
 *
 * Phpdoc utilitaire php pour generer de la doc
 *
 * Original script from : Stephane Philipakis <wwpakis&#64;free.fr>
 *
 * Permission d'utliser et de modifier ce logiciel ainsi que sa
 * documentation pour tout usage non commercial est accordee
 * sans autre charge supplmentaire du moment que l'auteur est
 * prvenu...
 * Meme chose pour la copie et la distribution,
 * du moment que cette notice de permission y figure.
 * Ce code est fourni 'tel quel' sans aucune garantie de ce
 * qu'il pourrait produire ou ne pas produire.
 *
 * Support    : http://sourceforge.net/projects/myphpmoney/
 * CVS        : http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/myphpmoney/
 */

// Define for PHPdoc entity.
  define('__UNDEFT__', 0); ## NDEFINI
  define('__CLASST__', 1); ## CLASS
  define('__FUNCT__',  2); ## FUNCTION
  define('__VART__',   3); ## VARIABLE
  define('__CMT__',    4); ## COMMENTAIRE

// Base class for PHPdoc entity.
class phpobj {

  // Type of the entity.
  // @see PHPscanner.linetype
  var $typ=__UNDEFT__;

  // Name of the entity.
  var $name;

  // Output HTML.
  function toHTML(){
  }
  // Output XML.
  function toXML(){
  }
}

// Comment object.
class cmtobj{
  // List of references (@see or @voir).
  var $voir = array();
  // Author.
  var $auteur = '';
  // Last modif date.
  var $dmodif = '';
  // Parameter list.
  var $param = array();
  // Result.
  var $rst = '';
  // Plain text.
  var $txt = '';
  // obsolete date.
  var $obsolete = '';

  // Prepare the object for output.
  // @param $txt The full comment code.
  // no translator the texte here because it's the define for source file
  function parse($txt){
    $l = explode ("\n",$txt);
    for ($i=0; $i<sizeof($l); $i++){
      $a = array();
      if (eregi("^[ \t]*@([^ \t]+)[ \t]+([^\n]+)",$l[$i],$a)){
                ## echo $a[1]." ".$a[2];
                $p = $a[1];
                $v = $a[2];
                if (($p == "voir")||($p=="see")){
                  $this->voir = explode(",",$v);
                }
                if (($p == "auteur")||($p=="author")){
                  $this->auteur = $v;
                }
                if ($p == "date"){
                  $this->dmodif = $v;
                }
                if ($p == "param"){
                  $ap=array();
                  ## echo ($v);
                  eregi("([^ \t]+)[ \t]+([^\n]*)",$v,$ap);
                  ## echo ($ap[2]);
                  $this->param[$ap[1]] = $ap[2];
                }
                if ($p == "result"){
                  $this->rst = $v;
                }
                if ($p == "obsolete"){
                  $this->obsolete = $v;
                }
      } else {
                $this->txt .= $l[$i]."\n";
      }
    }
     ## nl2br because php 4.05 for xhtml compliency : $this->txt = nl2br(trim($this->txt));
     $this->txt = str_replace("\n","<br />",trim($this->txt));
  }

  // Output HTML.
   function toHTML(){
    Global $_VAR;

    ## Compatibilite avec serveurs ne fournissant pas $REQUEST_URI (IIS par exemple)
    if (!isset($GLOBALS['_SERVER']['REQUEST_URI'])) {
      $GLOBALS['_SERVER']['REQUEST_URI'] = $GLOBALS['_SERVER']['PHP_SELF'];
       if (!strpos($GLOBALS['_SERVER']['REQUEST_URI'], '?') && isset($GLOBALS['_SERVER']['QUERY_STRING']))
          $GLOBALS['_SERVER']['REQUEST_URI'] .= '?'.$GLOBALS['_SERVER']['QUERY_STRING'];
    }
    $code_html = "<table class=\"TContenu70\"><tr><td>".str_replace('&lt;br /&gt;','<br />',htmlspecialchars($this->txt))."</td></tr></table>";
    if ($this->obsolete!=""){
    $code_html .= "<table class=\"TContenu70\"><tr class=\"phpdoc7\"><td>".$_VAR['PHPDOC_CLASS_1']." ".$this->obsolete."</td></tr></table>";
   }

    if (sizeof($this->param)!=0){
        $code_html .= $_VAR['PHPDOC_CLASS_2']."<br />";
      while(list($p,$v)=each($this->param)){
        $code_html .= "- ".$p." : ".$v."<br />";
      }
    }
    if ($this->rst != "")
    $code_html .= $_VAR['PHPDOC_CLASS_3']." ".$this->rst."<br />";

    if (sizeof($this->voir)!=0){
    $code_html .= $_VAR['PHPDOC_CLASS_4'];

      for ($i = 0 ; $i<sizeof($this->voir); $i++){
    if ($i>0) $code_html .= ",";
    $code_html .= "<a href=\"".str_replace('&lt;br /&gt;','<br />',htmlspecialchars($GLOBALS['_SERVER']['REQUEST_URI']))."#".$this->voir[$i]."\">".$this->voir[$i]."</a> ";
      }
      $code_html .= "<br />";
    }
    if ($this->auteur != "")
    $code_html .= $_VAR['PHPDOC_CLASS_5']." ".$this->auteur."<br />";
    if ($this->dmodif != "")
      $code_html .= $_VAR['SIMUL_FORM_2']." ".$this->dmodif."<br />";
      $code_html .= '<br />';
  return $code_html;
  }

  // Output XML.
  function toXML(){
    $code_xml  = "<COMMENT>\n";
    $code_xml .= "<TEXT>";
    $code_xml .= trim($this->txt);
    $code_xml .= "</TEXT>\n";

    if ($this->obsolete != "")
      $code_xml .= "<OBSOLETE date=\"".$this->obsolete."\"/>\n";

    if (sizeof($this->param)!=0){
      while(list($p,$v)=each($this->param)){
         $code_xml .= "<PARAM name=\"".$p."\">".$v."</PARAM>\n";
      }
    }
    if ($this->rst != "")
      $code_xml .= "<RESULT>".$this->rst."</RESULT>\n";

    if (sizeof($this->voir)!=0){
      for ($i = 0 ; $i<sizeof($this->voir); $i++){
    $code_xml .= "<SEE pnt=\"".$this->voir[$i]."\"/>\n";
      }
    }
    if ($this->auteur != "")
      $code_xml .= "<AUTHOR>".$this->auteur."</AUTHOR>\n";

    if ($this->dmodif != "")
      $code_xml .= "<DATE date=\"".$this->dmodif."\"/>\n";
    $code_xml .= "</COMMENT>\n";
  return $code_xml;
  }
}


// Function/Method object.
class funcobj extends phpobj {
  var $typ=__FUNCT__;
  var $params = '';
  var $name = '';
  var $desc = '';
  var $cls = '';

  // Constructor
  // @param $n Function name
  // @param $a Arguments string
  // @param $d Description
  function funcobj($n,$a,$d){
    $this->name = $n;
    $this->params = $a;
    $this->desc = $d;
  }

  function toHTML(){
    $code_html = "&nbsp;&nbsp;<span class=\"menubleubig\"><a id=\"".$this->cls.".".str_replace("$","",$this->name)."\"><span class=\"menubold\">".$this->name."</span></a></span>(".$this->params.")<br />";
    $d = new cmtobj;
    $code_html .= $d->parse($this->desc);
    $code_html .= $d->toHTML();
  return $code_html;
  }

  function toXML(){
    $code_xml = "<FUNCTION class=\"".$this->cls."\" name=\".".$this->name."\">\n";
    $d = new cmtobj;
    $code_xml .= $d->parse($this->desc);
    $code_xml .= $d->toXML();
    $code_xml .= "</FUNCTION>\n";
  return $code_xml;
  }
}

// Variable/Attribute object
class varobj extends phpobj {
  var $typ=__VART__;
  var $name = '';
  var $desc = '';
  var $cls = '';

  // Constructor
  // @param $n Variable name
  // @param $d Description
  function varobj($n,$d){
    $this->name = $n;
    $this->desc = $d;
  }

  function toHTML(){
    $code_html = "&nbsp;&nbsp;<span class=\"menubleubig\"><a id=\"".$this->cls.".".str_replace("$","",$this->name)."\"><span class=\"menubold\">".$this->name."</span></a></span><br />";
    $d = new cmtobj;
    $code_html .= $d->parse($this->desc);
    $code_html .= $d->toHTML();
  return $code_html;
  }

  function toXML(){
    $code_xml = "<VAR class=\"".$this->cls."\" name=\".".$this->name."\">\n";
    $d = new cmtobj;
    $code_xml .= $d->parse($this->desc);
    $code_xml .= $d->toXML();
    $code_xml .= "</VAR>\n";
   return $code_xml;
  }
}

// Class object
class classobj extends phpobj {
  var $typ = __CLASST__;
  var $attributs = array();
  var $methods = array();
  var $name = '';
  var $ext = '';
  var $desc = '';

  // Constructor
  // @param $n Class name
  // @param $a Parent class name
  // @param $d Description
  function classobj ($n, $a, $d){
    $this->name = $n;
    $this->ext  = $a;
    $this->desc = $d;
  }

  // Add an attribute object
  // @param $a The varobj object
  function addAttribut($a){
    ## echo "adding attribut ".$a->name." to class ".$this->name."<br />";
    $this->attributs[]=$a;
  }

  // Add an methode object
  // @param $a The funcobj object
  function addMethod($m){
    ## echo "adding method ".$m->name." to class ".$this->name."<br />";
    $this->methods[]=$m;
  }

  function toHTML(){
   Global $_VAR;
    $code_html  = "<div class=\"blockhr\"><hr /></div>\n";
    $code_html .= "<table class=\"TContenu100\"><tr><td class=\"phpdoc5\"><span class=\"texteBig\"><a id=\".".str_replace('$','',$this->name)."\">".$this->name."</a></span></td><td class=\"phpdoc5best\"><a href=\"".htmlspecialchars($GLOBALS['_SERVER']['REQUEST_URI'])."#".$_VAR['TOP']."\">".$_VAR['TOP']."</a></td></tr>\n";
    if ($this->ext != ""){
      $code_html .= "<tr><td class=\"phpdoc5\" colspan=\"2\"><span class=\"texte\">".$_VAR['PHPDOC_CLASS_8']." <a href=\"".htmlspecialchars($GLOBALS['_SERVER']['REQUEST_URI'])."#.".$this->ext."\">".$this->ext."</a></span></td></tr>\n";
    }
    $code_html .= "<tr class=\"phpdoc4\"><td colspan=\"2\">\n";
    $d = new cmtobj;
    $code_html .= $d->parse($this->desc);
    $code_html .= $d->toHTML();
    $code_html .= "</td></tr></table>\n";
    $code_html .= "<span class=\"menubold\">".$_VAR['PHPDOC_CLASS_6']."</span><ul>\n";

    for ($i = 0; $i<sizeof($this->attributs); $i++){
      $code_html .= "<li>".$this->attributs[$i]->toHTML()."</li>\n";
    }
    $code_html .= "</ul>";
    $code_html .= "<span class=\"menubold\">".$_VAR['PHPDOC_CLASS_7']."</span><ul>\n";

    for ($i = 0; $i<sizeof($this->methods); $i++){
      $code_html .= "<li>".$this->methods[$i]->toHTML()."</li>\n";
    }
    $code_html .= "</ul>\n";
  return $code_html;
  }


  function toXML(){
    $code_xml  = "<CLASS name=\"".$this->name."\" extends=\"".$this->ext."\">\n";

    $d = new cmtobj;
    $code_xml .= $d->parse($this->desc);
    $code_xml .= $d->toXML();
    for ($i = 0; $i<sizeof($this->attributs); $i++){
      $code_xml .= $this->attributs[$i]->toXML();
    }
    for ($i = 0; $i<sizeof($this->methods); $i++){
      $code_xml .= $this->methods[$i]->toXML();
    }
    $code_xml .= "</CLASS>\n";
   return $code_xml;
  }
}

// The PHPdoc scanner<br />
// Parses the source file and construct a array of PHPdoc objects.
// @see phpobj
class PHPscanner {
  // The result objects array
  var $objs = array();

  // Scans a file.
  // @param $fp A file pointer
  function scanFile($fp){
    $depth = 0;
    $inclass = false;
    $curobj = false;
    $maincmt = false;
    $othercmt = false;

    while (!(feof($fp))){
      // $l : line read.
      $l = trim(fgets($fp,4096));

      $lobj = linetype($l);
      if ($lobj->typ != __CMT__)
        $depth = get_depth($depth,$l);
      if (($depth == 0)&&($inclass)){
    ## if depth=0 and inclass = true : we just leave a class def...
    ## inclass = false
    ## add class object to object list
    $inclass = false;
    if ($curobj) $this->objs[] = $curobj;
      }
      ## Now switch on line type...
      switch($lobj->typ){
      case (__CLASST__):
    ## this is a class def line (class ... {)
    $obj = new classobj($lobj->name,$lobj->attr,$cmtbuff);
    ## reset comment buffer...
    $cmtbuff = '';
    ## current object becomes class object
    $curobj = $obj;
    ## inclass on true...
    $inclass = true;
    break;
      case (__FUNCT__):
    ## this is a function def line (function ...(...){)
    if ($depth<2){
      ## depth < 2, we are not in a class...
      $inclass = false;
    }
    $obj = new funcobj($lobj->name,$lobj->attr,$cmtbuff);

    if ($inclass){
      ## curobj is the class object.
      $obj->cls = $curobj->name;
      ## obj is one of his methods.
      $curobj->addMethod($obj);
    } else {
      ## curobj becomes this function object.
      $curobj = $obj;
      $this->objs[] = $obj;
    }
    ## reset the comment buffer.
    $cmtbuff = '';
    break;
      case (__VART__):
                ## this is a variable def line (var ...)
                if ($depth<1){
                  ## we are not in a class
                  $inclass = false;
                }
                ## create the new var object...
                $obj = new varobj($lobj->name, $cmtbuff);

                if ($inclass){
                  $obj->cls = $curobj->name;
                  $curobj->addAttribut($obj);
                } else {
                  $curobj = $curobj;
                  $this->objs[] = $obj;
                }

                $cmtbuff = '';
                break;
      case (__CMT__):
                ## this is a comment line. Add it to comment buffer.
                $cmtbuff .= $lobj->name;
                break;
      default:
    ## anything else, reset the comment buffer.
    $cmtbuff = '';
    break;
      }
    }
  }
}

// Return the type of the parsed line:
// __CLASST__    : Class definition start.
// __FUNCT__     : Function/Method definition start.
// __VART__      : Variable/Attribute declaration.
// __CMT__       : Comment line (ie : starting with //).
// __UNDEFT__    : Undefined.
// @param $l            : The line (String).
// @result The type of the line.
function linetype($l){
  $lobj = new phpobj;
  $a = array();

  if (eregi("^[ \t]*//([^\r\n]*)",$l,$a)) {
    $lobj->typ  = __CMT__;
    $lobj->attr = '';
    $lobj->name  = $a[1]."\n";
    return $lobj;
  }

  if (eregi("^[ \t]*class[ \t]+([^\ \t]+)[ \t]+extends[ \t]+([^\n {]+)",$l,$a)){
    $lobj->typ  = __CLASST__;
    $lobj->attr = $a[2];
    $lobj->name  = $a[1];
    return $lobj;
  }
  if (eregi("^[ \t]*class[ \t]+([^\ \t{]+)[ \t]*",$l,$a)){
    $lobj->typ  = __CLASST__;
    $lobj->attr = '';
    $lobj->name  = $a[1];
    return $lobj;
  }
  if (eregi("^[ \t]*function[ \t]+([^\ \t(]+)[ \t]*[(]([^)]*)",$l,$a)){
        $lobj->typ  = __FUNCT__;
        $lobj->attr = $a[2];
        $lobj->name  = $a[1];
        return $lobj;
  }
  if (eregi("^[ \t]*var[ \t]+([^\ \t=;]+)",$l,$a)){
    $lobj->typ  = __VART__;
    $lobj->attr = '';
    $lobj->name  = $a[1];
    return $lobj;
  }
  return $lobj;
}

// Return the depth of the parsed line (in script, class, function...)
// increase the depth on { decrease on }...
// @param $d The current depth.
// @param $l The line.
// @result The new depth.
function get_depth($d,$l){
  $instr=false;
  for ($i = 0; $i<strlen($l); $i++){
    if ($l[$i] == "\"")  $instr = !$instr;
    if (!$instr) {
      if ($l[$i] == "{") $d+=1;
      if ($l[$i] == "}") $d-=1;
    }
  }
  return $d;
}