2 //==============================================================================
4 // Description: Use parsing classes to generate a documentation skeleton
6 // Author: johanp@aditus.nu
7 // Version: $Id: jpgendoc.php,v 1.2 2003/01/30 14:55:57 aditus Exp $
10 // Copyright (C) 2001,2002 Johan Persson
11 //==============================================================================
12 include("jplintphp.php");
14 // Utility function to highlight a snippet of PHP code
15 function HighlightCodeSnippet($t,$bg=true) {
17 $t = highlight_string($t,true);
18 $t=str_replace('<?','',$t);
19 $t=str_replace('?>','',$t);
21 $t = "<div style=\"background-color:#E6E6E6;font-family:courier new;font-size:85%;font-weight:bold;\"><b>$t</b></div>";
24 $t = "<span style=\"font-family:courier;font-size:85%;font-weight:bold;\">$t</span>";
30 // Formatting class for Classes
31 class DocClassProp extends ClassProp {
34 function DocClassProp($aParent,$aName,$aLineNbr,$aFile) {
35 parent::ClassProp($aParent,$aName,$aLineNbr,$aFile);
38 function FormatVar($aVar) {
40 return HighlightCodeSnippet($aVar,false)."; ";
43 function FormatClass($aClass,$aParent) {
44 $res = "<div style=\"background-color:yellow;font-family:courier new;\">";
45 $res .= "CLASS <b>".$aClass."</b>";
47 $res .= " EXTENDS <b><i>$aParent</i></b>";
52 function PrettyPrintVars() {
53 $res = "<table border=0>\n";
54 for($i=0; $i<count($this->iVars); ++$i) {
55 $res .= "<tr><td valign=top>";
56 // highlight_string is buggy so we add ';' to be able to parse a
58 $t = $this->iVars[$i];
62 $t = ob_get_contents();
64 $t=str_replace('<?php ','',$t);
65 $t=str_replace('?>','',$t);
66 $res .= "<span style=\"font-family:times;font-size:85%;font-weight:bold;\">$t</span>\n";
67 //$res .= "</td><td valign=top> </td><td>".$this->[$i+1];
68 $res .= "</td></tr>\n";
75 // Formatting class for Methods
76 class DocFuncProp extends FuncProp {
77 function DocFuncProp($aClassName,$aName,$aLineNbr,$aArgs,$aArgsVal,$aShortComment) {
78 parent::FuncProp($aClassName,$aName,$aLineNbr,$aArgs,$aArgsVal,$aShortComment);
82 $res = $this->PrettyPrintFunc();
83 $res .= $this->PrettyPrintArgs();
84 $res .= "<b>Returns:</b>\n";
85 $res .= "<br><b>Description:</b><br>\n".str_replace('//','',$this->iShortComment);
86 $res .= "<br><b>Also see:</b>\n";
87 $res .= "<br><b>Example:</b><br> \n";
91 function PrettyPrintFunc() {
92 $t="function ".$this->GetName()."(";
93 for($i=0; $i<count($this->iArgs); ++$i) {
94 if( $i != 0 ) $t .= ",";
95 $t .= $this->iArgs[$i];
98 return HighlightCodeSnippet($t);
101 function PrettyPrintArgs() {
102 if( count($this->iArgs) == 0 )
104 $res = "<table border=0>\n";
105 for($i=0; $i<count($this->iArgs); ++$i) {
106 $res .= "<tr><td valign=top>";
107 // highlight_string is buggy so we add ';' to be able to parse a
109 $t = $this->iArgs[$i];
112 highlight_string($t);
113 $t = ob_get_contents();
115 $t=str_replace('<?php ','',$t);
116 $t=str_replace('?>','',$t);
117 $res .= "<span style=\"font-family:times;font-size:85%;font-weight:bold;\">$t</span>\n";
118 $res .= "</td><td valign=top> </td><td>XXXX</td></tr>\n";
120 $res .= "</table>\n";
126 class DocParser extends Parser {
127 function DocParser($aFile) {
128 parent::Parser($aFile);
130 // Factory function for classes
131 function NewClassProp($aParent,$aName,$aLineNbr,$aFileName) {
132 return new DocClassProp($aParent,$aName,$aLineNbr,$aFileName);
134 // Factory function for methods
135 function NewFuncProp($aClassName,$aName,$aLineNbr,$aArgs,$aArgsVal,$aShortComment) {
136 return new DocFuncProp($aClassName,$aName,$aLineNbr,$aArgs,$aArgsVal,$aShortComment);
138 // Map function for methods
139 function MapFunc(&$aFunc) {
140 parent::MapFunc($aFunc);
142 // map function for classes
143 function MapClass(&$aClass) {
144 parent::MapClass($aClass);
150 class DocDriver extends Driver {
151 function DocDriver($aFile) {
152 parent::Driver($aFile);
155 function NewParser($aFile) {
156 return new DocParser($aFile);
159 function PostProcessing() {
160 parent::PostProcessing();
161 $res = $this->iParser->GetUnusedClassVariables();
163 echo "<hr><h3>SUMMARY of unused instance variables</h3>$res";
164 $res = $this->iParser->GetWarnings();
166 echo "<hr><h3>SUMMARY of warnings</h3>$res";
171 //==========================================================================
172 // Script entry point
173 // Read URL argument and create Driver
174 //==========================================================================
175 if( !isset($HTTP_GET_VARS['target']) )
176 die("<b>No file specified.</b> Use 'mylintphp.php?target=file_name'" );
177 $file = urldecode($HTTP_GET_VARS['target']);
178 $driver = new DocDriver($file);