File: PhpdocHTMLClassRenderer.php

package info (click to toggle)
php4 4.0.3pl1-0potato3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 15,168 kB
  • ctags: 20,556
  • sloc: ansic: 155,237; php: 10,827; sh: 9,608; yacc: 1,874; lex: 1,742; makefile: 788; java: 424; awk: 359; cpp: 335; perl: 181; xml: 57
file content (367 lines) | stat: -rw-r--r-- 10,335 bytes parent folder | download
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
<?php
/**
* Renders classes.
*/
class PhpdocHTMLClassRenderer extends PhpdocHTMLDocumentRenderer {

	/**
	* Internal array of "&nbsp;" strings to format HTML output.
	* @var	array	$indent
	*/
	var $indent = array();
	
	/**
	* Array of variables found in the xml document.
	* @var	array	$variables
	*/
	var $variables = array();

	/**
	* Sets the xml and template root directory.
	* 
	* @param	string	XML file path
	* @param	string	Template file path
	* @param	string	Name of the current application
	* @see	setPath(), setTemplateRoot()
	*/
	function PhpdocHTMLClassRenderer($path, $templateRoot, $application) {
	
		$this->setPath($path);
		$this->setTemplateRoot($templateRoot);
		$this->application = $application;
		
		$this->accessor = new PhpdocClassAccessor;
		$this->tpl = new IntegratedTemplate($this->templateRoot);
		$this->fileHandler = new PhpdocFileHandler;
		
	} // end constructor

	/**
	* Renders a class
	* @param	string	XML source file
	* @param	string	Name of the HTML target file.
	* @access	public
	*/	
	function renderClass($xmlfile, $htmlfile="") {

		$this->tpl->loadTemplatefile("class.html");	

		if (""==$htmlfile)
			$htmlfile = substr($xmlfile, 6, -4).".html";

		$this->accessor->loadXMLFile($this->path.$xmlfile);
		
		$this->renderSubclasses();
		$this->renderInherited();
		$this->renderFunctions();
		$this->renderVariables();
		$this->renderUses();
		$this->renderConstants();
		
		$class = $this->accessor->getClassdata();

		$tplvars = array();
		
		$tplvars["CLASS_FILE"] 		= $class["file"]["value"];
		$tplvars["CLASS_NAME"] 		= $class["name"];
		$tplvars["CLASS_ACCESS"]	= $class["access"];
		$tplvars["CLASS_PACKAGE"]	= $class["package"];
	
		if (""!=$class["extends"])
			$tplvars["CLASS_EXTENDS"] = sprintf('extends <a href="%s.html">%s</a>', 
																						$class["extends"], 
																						$class["extends"]
																					);
			
		$tplvars["CLASS_UNDOC"] 	= ("true" == $class["undoc"]) ? $this->undocumented : "";
		
		$tplvars["CLASS_ABSTRACT"]= ("true" == $class["abstract"]) ? "abstract" : "";
		$tplvars["CLASS_STATIC"]	= ("true"	== $class["static"]) ? "static" : "";
		$tplvars["CLASS_FINAL"] 	= ("true" == $class["final"]) ? "final" : "";
		
		$tplvars["CLASS_TREE"] 		= $this->getClasstree($class["name"]);
		
		if (isset($class["doc"]["link"]))
			$this->renderLinks($class["doc"]["link"], "class_");
			
		if (isset($class["doc"]["author"]))
			$this->renderAuthors($class["doc"]["author"], "class_");
			
		if (isset($class["doc"]["see"]))
			$this->renderSee($class["doc"]["see"], "class_");
		
		$fields = array( 	"version", "deprecated", "copyright"	,
											"since", "magic");
		reset($fields);
		while (list($k, $field)=each($fields)) 
			if (isset($class["doc"][$field])) {
				$this->tpl->setCurrentBlock("class_".strtolower($field));
				$this->tpl->setVariable(strtoupper($field), $class["doc"][$field]["value"]);
				$this->tpl->parseCurrentBlock();
			}

		$fields = array( "description", "shortdescription" );
		reset($fields);
		while (list($k, $field)=each($fields)) 
			if (isset($class["doc"][$field]))
				$tplvars["CLASS_".strtoupper($field)] = $this->encode($class["doc"][$field]["value"]);

		$this->tpl->setCurrentBlock("__global__");				
		$this->tpl->setVariable($tplvars);
		$this->tpl->setVariable("APPNAME", $this->application);
		
		$this->fileHandler->createFile($this->path.$htmlfile, $this->tpl->get() );
		$this->tpl->free();	
		
	} // end func renderClass
	
		/**
	* Renders a list of inherited elements.
	* @see	renderInheritedElements()
	*/
	function renderInherited() {
		
		$this->renderInheritedElements(	$this->accessor->getInheritedFunctions(),
																		"inheritedfunctions",
																		"function"
																	);
																	
		$this->renderInheritedElements( $this->accessor->getInheritedVariables(),
																		"inheritedvariables",
																		"variable"
																	);

		$this->renderInheritedElements( $this->accessor->getInheritedConstants(),
																		"inheritedconstants",
																		"constant"
																	);																	

		$this->renderInheritedElements(	$this->accessor->getInheritedUses(),
																		"inheriteduses",
																		"uses"
																	);

	} // end func renderInherited
	
	/**
	* Renders a list of a certain inherited element.
	* @see	renderInheritedElements()
	*/
	function renderInheritedElements($inherited, $block, $type) {
		
		if (0==count($inherited))
			return;
			
		$this->tpl->setCurrentBlock($block);
		reset($inherited);
		while (list($source, $elements)=each($inherited)) {
			
			$value = "";
			reset($elements);
			while (list($k, $element)=each($elements))
				$value.= sprintf('<a href="%s.html#%s_%s">%s</a>, ', 
															$source,
															$type, 
															$element, 
															$element
													);
			$value = substr($value, 0, -2);
			
			$this->tpl->setVariable("SOURCE", $source);
			$this->tpl->setVariable("ELEMENTS", $value);
			$this->tpl->parseCurrentBlock();					
		}

	} // end func renderInheritedElements
	
	/**
	* Renders a list of direct known subclasses.
	*/
	function renderSubclasses() {
		
		$subclasses = $this->accessor->getSubclasses();
		if (0==count($subclasses)) 
			return;
		
		$elements = "";
		reset($subclasses);
		while (list($k, $subclass)=each($subclasses))
			$elements.= sprintf('<a href="%s.html">%s</a>, ', $subclass, $subclass);
		
		$elements	= substr($elements, 0, -2);
		
		if (""!=$elements) {
		
			$this->tpl->setCurrentBlock("subclasses");
			$this->tpl->setVariable("ELEMENTS", $elements);
			$this->tpl->parseCurrentBlock();

		}
	} // end func renderSubclasses
	
	/**
	* Adds a summary and a detailed list of all variables to the template.
	* @see	renderVariableSummary(), renderVariableDetail()
	*/
	function renderVariables() {
		
		$this->variables["private"] = $this->accessor->getVariablesByAccess("private");
		$this->variables["public"] 	= $this->accessor->getVariablesByAccess("public");
		
		if (0==count($this->variables["private"]) && 0==count($this->variables["public"]))
			return;
		
		$this->renderVariableSummary();
		$this->renderVariableDetail();

		$this->variables = array();
		
	} // end func renderVariables

	/**
	* Adds a summary of all variables to the template.
	* 
	* The function assumes that there is a block named "variablesummary" and
	* within it a block names "variablesummay_loop" in the template.
	*
	* @see	renderVariableDetail()
	*/	
	function renderVariableSummary() {	

		reset($this->accessModifiers);
		while (list($k, $access)=each($this->accessModifiers)) {
			if (0==count($this->variables[$access]))
				continue;
				
			$this->tpl->setCurrentBlock("variablesummary_loop");
			
			reset($this->variables[$access]);
			while (list($name, $variable)=each($this->variables[$access])) {
				
				$this->tpl->setVariable("NAME", $name);
				$this->tpl->setVariable("TYPE", $variable["type"]);
				
				if (isset($variable["doc"]["shortdescription"]))
					$this->tpl->setVariable("SHORTDESCRIPTION", $this->encode($variable["doc"]["shortdescription"]["value"]));
			
				$this->tpl->parseCurrentBlock();				
				
			}
			
			$this->tpl->setCurrentBlock("variablesummary");
			$this->tpl->setVariable("ACCESS", ucfirst($access));
			$this->tpl->parseCurrentBlock();
			
		}

	} // end func renderVariableSummary

	/**
	* Adds a detailed list of all variables to the template.
	* 
	* The function assumes that there is a block named "variabledetails"
	* and within it a block names "variablesdetails_loop" in the template.
	*
	* @see	renderVariableSummary()
	*/	
	function renderVariableDetail() {
		
		reset($this->accessModifiers);
		while (list($k, $access)=each($this->accessModifiers)) {
			if (0==count($this->variables[$access]))
				continue;
			
			reset($this->variables[$access]);
			while (list($name, $variable)=each($this->variables[$access])) {
			
				$tplvars = array();
				$tplvars["NAME"] 		=	$variable["name"];
				$tplvars["ACCESS"] 	= $variable["access"];
				$tplvars["TYPE"] 		= $variable["type"];
				$tplvars["VALUE"]		= htmlentities($variable["value"]);
				
				if ("true"==$variable["undoc"]) 
					$tplvars["UNDOC"] = $this->undocumented;
				
				if ("true"==$variable["static"])
					$tplvars["STATIC"] = "static";
					
				if ("true"==$variable["final"])
					$tplvars["FINAL"] = "final";

				if (isset($variable["doc"]["shortdescription"]))
					$tplvars["SHORTDESCRIPTION"] = $this->encode($variable["doc"]["shortdescription"]["value"]);
				if (isset($variable["doc"]["description"]))
					$tplvars["DESCRIPTION"] = $this->encode($variable["doc"]["description"]["value"]);
					
				$this->renderCommonDocfields("variabledetails_", $variable);
				
				$this->tpl->setCurrentBlock("variabledetails_loop");	
				$this->tpl->setVariable($tplvars);
				$this->tpl->parseCurrentBlock();	
			}

			$this->tpl->setCurrentBlock("variabledetails");
			$this->tpl->setVariable("ACCESS", ucfirst($access) );
			$this->tpl->parseCurrentBlock();
		}		
		
	} // end func renderVariableDetail

	/**
	* Returns a html string that shows the class tree.
	* @param	string	name of the current class
	* @return	string	HTML that shows the tree
	*/	
	function getClasstree($class) {
		
		$path = $this->accessor->getClasstree();
		
		$level = 0;
		$num = count($path)-1;
		
		for ($i = $num; $i>=0; $i--) {

			$indent = $this->getIndent($level);
			if ($level>0)
				$value.= sprintf("%s |<br>%s+-- ", $indent, $indent);
			$value.= sprintf('<a href="%s.html">%s</a><br>', 
												$path[$i],
												$path[$i]
											);
			$level++;
			
		}

		$indent = $this->getIndent($level);
		if ($level>0)
			$value.= sprintf("%s |<br>%s+-- ", $indent, $indent);
		$value.= sprintf('%s<br>', $class);
			
		return $value;
	} // end func getClasstree

	/**
	* Returns a certain number of "&nbsp;"s.
	* @param	int	number of "&nbsp;" required.
	* @see		$indent
	* @return	string	A string with the requested number of nunbreakable html spaces
	*/
	function getIndent($level) {
		
		if (!isset($this->indent[$level])) {
		
			$html = "";
			for ($i=0; $i<$level; $i++)
				$html.= "&nbsp;&nbsp;";
			
			$this->indent[$level] = $html;
			
		}
		
		return $this->indent[$level];
			
	} // end func getIndent
	
} // end class PhpdocHTMLClassRenderer
?>