5 * @version $Id: PhpdocHTMLClassRenderer.php,v 1.4 2000/12/03 22:37:37 uw Exp $
\r
7 class PhpdocHTMLClassRenderer extends PhpdocHTMLDocumentRenderer {
\r
10 * Internal array of " " strings to format HTML output.
\r
12 * @var array $indent
\r
14 var $indent = array();
\r
17 * Array of variables found in the xml document.
\r
19 * @var array $variables
\r
21 var $variables = array();
\r
24 * Sets the xml and template root directory.
\r
26 * @param string XML file path
\r
27 * @param string Template file path
\r
28 * @param string Name of the current application
\r
29 * @param string Filename extension
\r
30 * @see setPath(), setTemplateRoot()
\r
32 function PhpdocHTMLClassRenderer($path, $templateRoot, $application, $extension = ".html") {
\r
34 $this->setPath($path);
\r
35 $this->setTemplateRoot($templateRoot);
\r
36 $this->application = $application;
\r
37 $this->file_extension = $extension;
\r
39 $this->accessor = new PhpdocClassAccessor;
\r
40 $this->tpl = new IntegratedTemplate($this->templateRoot);
\r
41 $this->fileHandler = new PhpdocFileHandler;
\r
43 } // end constructor
\r
48 * @param string XML source file
\r
49 * @param string Name of the HTML target file.
\r
52 function renderClass($xmlfile, $htmlfile = "") {
\r
54 $this->tpl->loadTemplatefile("class.html");
\r
55 if ("" == $htmlfile)
\r
56 $htmlfile = substr($xmlfile, 6, -4) . $this->file_extension;
\r
58 $this->accessor->loadXMLFile($this->path.$xmlfile);
\r
60 $this->renderSubclasses();
\r
61 $this->renderInherited();
\r
62 $this->renderFunctions();
\r
63 $this->renderVariables();
\r
64 $this->renderUses();
\r
65 $this->renderConstants();
\r
67 $class = $this->accessor->getClassdata();
\r
70 $tplvars["CLASS_FILE"] = $class["file"]["value"];
\r
71 $tplvars["CLASS_NAME"] = $class["name"];
\r
72 $tplvars["CLASS_ACCESS"] = $class["access"];
\r
73 $tplvars["CLASS_PACKAGE"] = $class["package"];
\r
75 if ("" != $class["extends"])
\r
76 $tplvars["CLASS_EXTENDS"] = sprintf('extends <a href="%s">%s</a>',
\r
77 $class["extends"].$this->file_extension,
\r
81 $tplvars["CLASS_UNDOC"] = ("true" == $class["undoc"]) ? $this->undocumented : "";
\r
83 $tplvars["CLASS_ABSTRACT"] = ("true" == $class["abstract"]) ? "abstract" : "";
\r
84 $tplvars["CLASS_STATIC"] = ("true" == $class["static"]) ? "static" : "";
\r
85 $tplvars["CLASS_FINAL"] = ("true" == $class["final"]) ? "final" : "";
\r
87 $tplvars["CLASS_TREE"] = $this->getClasstree($class["name"]);
\r
89 if (isset($class["doc"]["link"]))
\r
90 $this->renderLinks($class["doc"]["link"], "class_");
\r
92 if (isset($class["doc"]["author"]))
\r
93 $this->renderAuthors($class["doc"]["author"], "class_");
\r
95 if (isset($class["doc"]["see"]))
\r
96 $this->renderSee($class["doc"]["see"], "class_");
\r
98 $fields = array( "version", "deprecated", "copyright", "since", "magic");
\r
100 while (list($k, $field) = each($fields))
\r
101 if (isset($class["doc"][$field])) {
\r
102 $this->tpl->setCurrentBlock("class_".strtolower($field));
\r
103 $this->tpl->setVariable(strtoupper($field), $class["doc"][$field]["value"]);
\r
104 $this->tpl->parseCurrentBlock();
\r
107 $fields = array( "description", "shortdescription" );
\r
110 while (list($k, $field)=each($fields))
\r
111 if (isset($class["doc"][$field]))
\r
112 $tplvars["CLASS_".strtoupper($field)] = $this->encode($class["doc"][$field]["value"]);
\r
114 $this->tpl->setCurrentBlock("__global__");
\r
115 $this->tpl->setVariable($tplvars);
\r
116 $this->tpl->setVariable("APPNAME", $this->application);
\r
118 $this->fileHandler->createFile($this->path.$htmlfile, $this->tpl->get() );
\r
119 $this->tpl->free();
\r
121 } // end func renderClass
\r
126 * Renders a list of inherited elements.
\r
128 * @see renderInheritedElements()
\r
130 function renderInherited() {
\r
132 $this->renderInheritedElements( $this->accessor->getInheritedFunctions(),
\r
133 "inheritedfunctions",
\r
137 $this->renderInheritedElements( $this->accessor->getInheritedVariables(),
\r
138 "inheritedvariables",
\r
142 $this->renderInheritedElements( $this->accessor->getInheritedConstants(),
\r
143 "inheritedconstants",
\r
147 $this->renderInheritedElements( $this->accessor->getInheritedUses(),
\r
152 } // end func renderInherited
\r
155 * Renders a list of a certain inherited element.
\r
157 * @param array List of inherited elements.
\r
158 * @param string Templateblockname
\r
159 * @param string Element type: function, variable...
\r
160 * @see renderInherited()
\r
162 function renderInheritedElements($inherited, $block, $type) {
\r
164 if (0 == count($inherited))
\r
167 $this->tpl->setCurrentBlock($block);
\r
170 while (list($source, $elements) = each($inherited)) {
\r
175 while (list($k, $element) = each($elements))
\r
176 $value .= sprintf('<a href="%s#%s_%s">%s</a>, ',
\r
177 $source.$this->file_extension,
\r
182 $value = substr($value, 0, -2);
\r
184 $this->tpl->setVariable("SOURCE", $source);
\r
185 $this->tpl->setVariable("ELEMENTS", $value);
\r
186 $this->tpl->parseCurrentBlock();
\r
189 } // end func renderInheritedElements
\r
192 * Renders a list of direct known subclasses.
\r
194 function renderSubclasses() {
\r
196 $subclasses = $this->accessor->getSubclasses();
\r
197 if (0 == count($subclasses))
\r
201 reset($subclasses);
\r
202 while (list($k, $subclass) = each($subclasses))
\r
203 $elements .= sprintf('<a href="%s">%s</a>, ', $subclass.$this->file_extension, $subclass);
\r
205 $elements = substr($elements, 0, -2);
\r
207 if ("" != $elements) {
\r
209 $this->tpl->setCurrentBlock("subclasses");
\r
210 $this->tpl->setVariable("ELEMENTS", $elements);
\r
211 $this->tpl->parseCurrentBlock();
\r
214 } // end func renderSubclasses
\r
217 * Adds a summary and a detailed list of all variables to the template.
\r
219 * @see renderVariableSummary(), renderVariableDetail()
\r
221 function renderVariables() {
\r
223 $this->variables["private"] = $this->accessor->getVariablesByAccess("private");
\r
224 $this->variables["public"] = $this->accessor->getVariablesByAccess("public");
\r
226 if (0 == count($this->variables["private"]) && 0 == count($this->variables["public"]))
\r
229 $this->renderVariableSummary();
\r
230 $this->renderVariableDetail();
\r
232 $this->variables = array();
\r
234 } // end func renderVariables
\r
237 * Adds a summary of all variables to the template.
\r
239 * The function assumes that there is a block named "variablesummary" and
\r
240 * within it a block names "variablesummay_loop" in the template.
\r
242 * @see renderVariableDetail()
\r
244 function renderVariableSummary() {
\r
246 reset($this->accessModifiers);
\r
247 while (list($k, $access) = each($this->accessModifiers)) {
\r
249 if (0 == count($this->variables[$access]))
\r
252 $this->tpl->setCurrentBlock("variablesummary_loop");
\r
254 reset($this->variables[$access]);
\r
255 while (list($name, $variable) = each($this->variables[$access])) {
\r
257 $this->tpl->setVariable("NAME", $name);
\r
258 $this->tpl->setVariable("TYPE", $variable["type"]);
\r
260 if (isset($variable["doc"]["shortdescription"]))
\r
261 $this->tpl->setVariable("SHORTDESCRIPTION", $this->encode($variable["doc"]["shortdescription"]["value"]));
\r
263 $this->tpl->parseCurrentBlock();
\r
267 $this->tpl->setCurrentBlock("variablesummary");
\r
268 $this->tpl->setVariable("ACCESS", ucfirst($access));
\r
269 $this->tpl->parseCurrentBlock();
\r
273 } // end func renderVariableSummary
\r
276 * Adds a detailed list of all variables to the template.
\r
278 * The function assumes that there is a block named "variabledetails"
\r
279 * and within it a block names "variablesdetails_loop" in the template.
\r
281 * @see renderVariableSummary()
\r
283 function renderVariableDetail() {
\r
285 reset($this->accessModifiers);
\r
286 while (list($k, $access) = each($this->accessModifiers)) {
\r
288 if (0 == count($this->variables[$access]))
\r
291 reset($this->variables[$access]);
\r
292 while (list($name, $variable)=each($this->variables[$access])) {
\r
294 $tplvars = array();
\r
295 $tplvars["NAME"] = $variable["name"];
\r
296 $tplvars["ACCESS"] = $variable["access"];
\r
297 $tplvars["TYPE"] = $variable["type"];
\r
298 $tplvars["VALUE"] = htmlentities($variable["value"]);
\r
300 if ("true" == $variable["undoc"])
\r
301 $tplvars["UNDOC"] = $this->undocumented;
\r
303 if ("true" == $variable["static"])
\r
304 $tplvars["STATIC"] = "static";
\r
306 if ("true" == $variable["final"])
\r
307 $tplvars["FINAL"] = "final";
\r
309 if (isset($variable["doc"]["shortdescription"]))
\r
310 $tplvars["SHORTDESCRIPTION"] = $this->encode($variable["doc"]["shortdescription"]["value"]);
\r
312 if (isset($variable["doc"]["description"]))
\r
313 $tplvars["DESCRIPTION"] = $this->encode($variable["doc"]["description"]["value"]);
\r
315 $this->renderCommonDocfields("variabledetails_", $variable);
\r
317 $this->tpl->setCurrentBlock("variabledetails_loop");
\r
318 $this->tpl->setVariable($tplvars);
\r
319 $this->tpl->parseCurrentBlock();
\r
323 $this->tpl->setCurrentBlock("variabledetails");
\r
324 $this->tpl->setVariable("ACCESS", ucfirst($access) );
\r
325 $this->tpl->parseCurrentBlock();
\r
329 } // end func renderVariableDetail
\r
332 * Returns a html string that shows the class tree.
\r
334 * @param string name of the current class
\r
335 * @return string HTML that shows the tree
\r
337 function getClasstree($class) {
\r
339 $path = $this->accessor->getClasstree();
\r
341 $num = count($path) - 1;
\r
343 for ($i = $num; $i >= 0; --$i) {
\r
345 $indent = $this->getIndent($level);
\r
348 $value.= sprintf("%s |<br>%s+-- ", $indent, $indent);
\r
350 $value.= sprintf('<a href="%s">%s</a><br>',
\r
351 $path[$i].$this->file_extension,
\r
358 $indent = $this->getIndent($level);
\r
361 $value.= sprintf("%s |<br>%s+-- ", $indent, $indent);
\r
363 $value.= sprintf('%s<br>', $class);
\r
366 } // end func getClasstree
\r
369 * Returns a certain number of " "s.
\r
371 * @param int number of " " required.
\r
373 * @return string A string with the requested number of nunbreakable html spaces
\r
375 function getIndent($level) {
\r
377 if (!isset($this->indent[$level])) {
\r
380 for ($i = 0; $i < $level; ++$i)
\r
381 $html .= " ";
\r
383 $this->indent[$level] = $html;
\r
387 return $this->indent[$level];
\r
388 } // end func getIndent
\r
390 } // end class PhpdocHTMLClassRenderer
\r