* * Permission d'utliser et de modifier ce logiciel ainsi que sa * documentation pour tout usage non commercial est accordee * sans autre charge supplémentaire du moment que l'auteur est * prévenu... * 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; $ivoir = 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","
",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 = "
".str_replace('<br />','
',htmlspecialchars($this->txt))."
"; if ($this->obsolete!=""){ $code_html .= "
".$_VAR["PHPDOC_CLASS_1"]." ".$this->obsolete."
"; } if (sizeof($this->param)!=0){ $code_html .= $_VAR["PHPDOC_CLASS_2"]."
"; while(list($p,$v)=each($this->param)){ $code_html .= "- ".$p." : ".$v."
"; } } if ($this->rst != "") $code_html .= $_VAR["PHPDOC_CLASS_3"]." ".$this->rst."
"; if (sizeof($this->voir)!=0){ $code_html .= $_VAR["PHPDOC_CLASS_4"]; for ($i = 0 ; $ivoir); $i++){ if ($i>0) $code_html .= ","; $code_html .= "',htmlspecialchars($GLOBALS['_SERVER']['REQUEST_URI']))."#".$this->voir[$i]."\">".$this->voir[$i]." "; } $code_html .= "
"; } if ($this->auteur != "") $code_html .= $_VAR["PHPDOC_CLASS_5"]." ".$this->auteur."
"; if ($this->dmodif != "") $code_html .= $_VAR["SIMUL_FORM_2"]." ".$this->dmodif."
"; $code_html .= "
"; return $code_html; } // Output XML. function toXML(){ $code_xml = "\n"; $code_xml .= ""; $code_xml .= trim($this->txt); $code_xml .= "\n"; if ($this->obsolete != "") $code_xml .= "obsolete."\"/>\n"; if (sizeof($this->param)!=0){ while(list($p,$v)=each($this->param)){ $code_xml .= "".$v."\n"; } } if ($this->rst != "") $code_xml .= "".$this->rst."\n"; if (sizeof($this->voir)!=0){ for ($i = 0 ; $ivoir); $i++){ $code_xml .= "voir[$i]."\"/>\n"; } } if ($this->auteur != "") $code_xml .= "".$this->auteur."\n"; if ($this->dmodif != "") $code_xml .= "dmodif."\"/>\n"; $code_xml .= "\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 = "  cls.".".str_replace("$","",$this->name)."\">".$this->name."(".$this->params.")
"; $d = new cmtobj; $code_html .= $d->parse($this->desc); $code_html .= $d->toHTML(); return $code_html; } function toXML(){ $code_xml = "cls."\" name=\".".$this->name."\">\n"; $d = new cmtobj; $code_xml .= $d->parse($this->desc); $code_xml .= $d->toXML(); $code_xml .= "\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 = "  cls.".".str_replace("$","",$this->name)."\">".$this->name."
"; $d = new cmtobj; $code_html .= $d->parse($this->desc); $code_html .= $d->toHTML(); return $code_html; } function toXML(){ $code_xml = "cls."\" name=\".".$this->name."\">\n"; $d = new cmtobj; $code_xml .= $d->parse($this->desc); $code_xml .= $d->toXML(); $code_xml .= "\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."
"; $this->attributs[]=$a; } // Add an methode object // @param $a The funcobj object function addMethod($m){ ## echo "adding method ".$m->name." to class ".$this->name."
"; $this->methods[]=$m; } function toHTML(){ Global $_VAR; $code_html = "

\n"; $code_html .= "\n"; if ($this->ext != ""){ $code_html .= "\n"; } $code_html .= "
name)."\">".$this->name."".$_VAR["TOP"]."
".$_VAR["PHPDOC_CLASS_8"]." ext."\">".$this->ext."
\n"; $d = new cmtobj; $code_html .= $d->parse($this->desc); $code_html .= $d->toHTML(); $code_html .= "
\n"; $code_html .= "".$_VAR["PHPDOC_CLASS_6"].""; $code_html .= "".$_VAR["PHPDOC_CLASS_7"]."\n"; return $code_html; } function toXML(){ $code_xml = "name."\" extends=\"".$this->ext."\">\n"; $d = new cmtobj; $code_xml .= $d->parse($this->desc); $code_xml .= $d->toXML(); for ($i = 0; $iattributs); $i++){ $code_xml .= $this->attributs[$i]->toXML(); } for ($i = 0; $imethods); $i++){ $code_xml .= $this->methods[$i]->toXML(); } $code_xml .= "\n"; return $code_xml; } } // The PHPdoc scanner
// 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