[ Index ] |
PHP Cross Reference of phpwcms V1.4.7 _r403 (01.11.10) |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 Copyright (C) 2004 Renato Coelho 4 (PHP)Source 2 Doc v0.5.0 5 This is a simple script created in order to update the HTML2FPDF page 6 It should make a php class documentation 7 LICENSE: Freeware. 8 Lacks: html_decode and the likes 9 Plans: make an independent table for each part? 10 11 Usage: 12 13 require_once('source2doc.php'); 14 echo source2doc('filename.php'); //Print doc info on browser 15 16 HOW TO declare var types and HOW TO use @return and @desc: (//! is a one-line comment) 17 18 var $name; //! type 19 20 function name() 21 { 22 //! @return void 23 //! @desc Say something in one line, but dont use tags or ';' here 24 //! @desc Fale algo em uma linha, mas nao use tags ou ';' aqui 25 ...} 26 27 */ 28 29 function source2doc( $filename ) 30 { 31 define( 'endl', "\n" ); 32 $classname = ''; 33 $extends = ''; 34 35 $file = fopen( $filename, "r" ); 36 $tamarquivo = filesize( $filename ); 37 $buffer = fread( $file, $tamarquivo ); 38 fclose( $file ); 39 // // 40 // Remove all PHP comments 41 // Leave only the special comments '//!' 42 // // 43 // Remove /* multi-line comments */ 44 $regexp = '|/\\*.*?\\*/|s'; 45 $buffer = preg_replace( $regexp, '', $buffer ); 46 // Remove // one line comments 47 $regexp = '|//[^!].*|m'; 48 $buffer = preg_replace( $regexp, '', $buffer ); 49 // // 50 // Get class name and what it extends (or not) 51 // // 52 $regexp = '|class\\s+?(\\S+)(\\s+?\\S+\\s+?(\\S+))?|mi'; 53 preg_match( $regexp, $buffer, $aux ); //one class per source file 54 $classname = $aux[1]; 55 if ( !empty( $aux[3] ) ) $extends = $aux[3]; 56 else $extends = ''; 57 58 $html = '<b>CLASSNAME:</b> ' . $classname . '<br />' . endl; 59 if ( $extends != '' ) $html .= '<b>EXTENDS:</b> ' . $extends . '<br />' . endl; 60 $html .= '<table border="1" width="100%">' . endl; 61 // // 62 // Get constants from source code 63 // // 64 $html .= '<tr>' . endl; 65 $html .= '<th bgcolor="#6191ff" colspan="2">' . endl; 66 $html .= 'CONSTANTS' . endl; 67 $html .= '</th>' . endl; 68 $html .= '</tr>' . endl; 69 70 $regexp = '/define[(](.*?);/si'; 71 preg_match_all( $regexp, $buffer, $const ); 72 73 $const = $const[0]; 74 for( $i = 0; $i < count( $const ) ; $i++ ) { 75 $html .= '<tr>' . endl; 76 $html .= '<td colspan="2">' . endl; 77 $html .= '<font size=2>' . $const[$i] . '</font>' . endl; 78 $html .= '</td>' . endl; 79 $html .= '</tr>' . endl; 80 } 81 // // 82 // Get imports from source code 83 // // 84 $html .= '<tr>' . endl; 85 $html .= '<th bgcolor="#6191ff" colspan="2">' . endl; 86 $html .= 'IMPORTS' . endl; 87 $html .= '</th>' . endl; 88 $html .= '</tr>' . endl; 89 90 $regexp = '/((require|include)[(_].*?);/si'; 91 preg_match_all( $regexp, $buffer, $imports ); 92 93 $imports = $imports[0]; 94 for( $i = 0; $i < count( $imports ) ; $i++ ) { 95 $html .= '<tr>' . endl; 96 $html .= '<td colspan="2">' . endl; 97 $html .= '<font size=2>' . $imports[$i] . '</font>' . endl; 98 $html .= '</td>' . endl; 99 $html .= '</tr>' . endl; 100 } 101 // // 102 // Get attributes from class 103 // // 104 $html .= '<tr>' . endl; 105 $html .= '<th bgcolor="#6191ff" colspan="2">' . endl; 106 $html .= 'ATTRIBUTES' . endl; 107 $html .= '</th>' . endl; 108 $html .= '</tr>' . endl; 109 110 $regexp = '|var\\s(.+);\\s*(//!\\s*?(\\S+))?|mi'; 111 preg_match_all( $regexp, $buffer, $atr ); 112 113 $vname = $atr[1]; 114 $vtype = $atr[3]; 115 116 if ( !empty( $vname ) ) { 117 $html .= '<tr>' . endl; 118 $html .= '<td align="center" width="10%" bgcolor="#bbbbbb">' . endl; 119 $html .= 'TYPE' . endl; 120 $html .= '</td>' . endl; 121 $html .= '<td align="center" width="90%" bgcolor="#bbbbbb">' . endl; 122 $html .= 'NAME' . endl; 123 $html .= '</td>' . endl; 124 $html .= '</tr>' . endl; 125 } 126 127 for( $i = 0; $i < count( $vname ) ; $i++ ) { 128 $html .= '<tr>' . endl; 129 130 $html .= '<td align="center">' . endl; 131 if ( empty( $vtype[$i] ) ) $html .= '<font size=2><i>(???)</i></font>' . endl; 132 else $html .= '<font size=2><i>(' . $vtype[$i] . ')</i></font>' . endl; 133 $html .= '</td>' . endl; 134 135 $html .= '<td>' . endl; 136 $html .= '<font size=2><b>var</b> ' . $vname[$i] . ';</font>' . endl; 137 $html .= '</td>' . endl; 138 $html .= '</tr>' . endl; 139 } 140 // /// 141 // Get class' methods 142 // /// 143 $html .= '<tr>' . endl; 144 $html .= '<th bgcolor="#6191ff" colspan="2">' . endl; 145 $html .= 'METHODS' . endl; 146 $html .= '</th>' . endl; 147 $html .= '</tr>' . endl; 148 149 $regexp = '|function\\s([^)]*)[)].*?(//!.*?)*;|si'; 150 preg_match_all( $regexp, $buffer, $func ); 151 152 $funcname = $func[1]; 153 $funccomment = $func[0]; 154 155 for( $i = 0; $i < count( $funcname ) ; $i++ ) { 156 $html .= '<tr>' . endl; 157 $html .= '<td bgcolor="#33ff99" colspan="2">' . endl; 158 $html .= '<font size=2><b>function</b> ' . $funcname[$i] . ')</font>' . endl; 159 $html .= '</td>' . endl; 160 $html .= '</tr>' . endl; 161 162 $desc = ''; 163 $ret = ''; 164 $regexp = '|//!(.*)|mi'; 165 preg_match_all( $regexp, $funccomment[$i], $temp ); 166 $temp = $temp[1]; 167 168 if ( empty( $temp[0] ) ) continue; 169 foreach( $temp as $val ) { 170 if ( strstr( $val, '@desc' ) ) { 171 $regexp = '|.*?@desc(.*)|si'; 172 preg_match( $regexp, $val, $temp2 ); 173 $desc = $temp2[1]; 174 } elseif ( strstr( $val, '@return' ) ) { 175 $regexp = '|.*?@return(.*)|si'; 176 preg_match( $regexp, $val, $temp3 ); 177 $ret = $temp3[1]; 178 } 179 } 180 if ( $ret != '' or $desc != '' ) { 181 $html .= '<tr>' . endl; 182 // @return column 183 $html .= '<td width="30%">' . endl; 184 if ( $ret == '' ) $html .= '<font size=2><b>Return:</b> <i>?void?</i></font>' . endl; 185 else $html .= '<font size=2><b>Return:</b> <i>' . trim( $ret ) . '</i></font>' . endl; 186 $html .= '</td>' . endl; 187 // @desc column 188 $html .= '<td width="70%">' . endl; 189 if ( $desc == '' ) $html .= '<font size=2><b>OBS:</b> </font>' . endl; 190 else $html .= '<font size=2><b>OBS:</b> ' . trim( $desc ) . '</font>' . endl; 191 $html .= '</td>' . endl; 192 193 $html .= '</tr>' . endl; 194 } 195 } 196 // /// 197 $html .= '</table>'; 198 199 return $html; 200 } 201 202 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Nov 16 22:51:00 2010 | Cross-referenced by PHPXref 0.7 |