3 * Provides functioninality to render modules and classes.
\r
5 * @version $Id: PhpdocHTMLDocumentRenderer.php,v 1.4 2000/12/03 22:37:37 uw Exp $
\r
7 class PhpdocHTMLDocumentRenderer extends PhpdocHTMLRenderer {
\r
10 * Message displayed if an object lacks documentation.
\r
12 * @var string $undocumented
\r
15 var $undocumented = "Warning: documentation is missing.";
\r
18 * Array of functions found in the xml document.
\r
20 * @var array $functions
\r
22 var $functions = array();
\r
25 * Array of included files.
\r
29 var $uses = array();
\r
32 * Array of constants.
\r
34 * @var array $constants
\r
36 var $constants = array();
\r
39 * Array of access modifiers.
\r
41 * @var array $accessModifiers
\r
43 var $accessModifiers = array("public", "private");
\r
46 * Array of doc container fields that get mapped directly to templateblocks.
\r
48 * @var array $simpleDocfields
\r
49 * @see renderVariableDetail()
\r
51 var $simpleDocfields = array(
\r
52 "VERSION" => "version",
\r
54 "DEPRECATED" => "deprecated",
\r
55 "COPYRIGHT" => "copyright",
\r
60 * Types of include statements.
\r
62 * @var array $usesTypes
\r
65 var $usesTypes = array( "include", "include_once", "require", "require_once" );
\r
68 * Adds a summary and a detailed list of all constants to the template.
\r
70 * @see renderConstantSummary(), renderConstantDetail()
\r
72 function renderConstants() {
\r
74 $this->constants["public"] = $this->accessor->getConstantsByAccess("public");
\r
75 $this->constants["private"] = $this->accessor->getConstantsByAccess("private");
\r
77 if (0 == count($this->constants["public"]) && 0 == count($this->constants["private"]))
\r
80 $this->renderConstantSummary();
\r
81 $this->renderConstantDetail();
\r
82 $this->constants = array();
\r
84 } // end func renderConstants
\r
87 * Adds a summary of all constants to the template.
\r
89 * The function assumes that there is a block called "constantssummary" and
\r
90 * withing this block a bock called "constantssummary_loop" in the template.
\r
92 * @see renderConstantDetail()
\r
94 function renderConstantSummary() {
\r
96 reset($this->accessModifiers);
\r
97 while (list($k, $access) = each($this->accessModifiers)) {
\r
98 if (0 == count($this->constants[$access]))
\r
101 $this->tpl->setCurrentBlock("constantssummary_loop");
\r
103 reset($this->constants[$access]);
\r
104 while (list($name, $const) = each($this->constants[$access])) {
\r
106 $this->tpl->setVariable("NAME", $name);
\r
107 $this->tpl->setVariable("VALUE", htmlentities($const["value"]));
\r
109 if (isset($const["doc"]["shortdescription"]))
\r
110 $this->tpl->setVariable("SHORTDESCRIPTION", $this->encode($const["doc"]["shortdescription"]["value"]));
\r
112 if ("true" == $const["undoc"])
\r
113 $this->tpl->setVariable("UNDOC", $this->undocumented);
\r
115 $this->tpl->parseCurrentBlock();
\r
118 $this->tpl->setCurrentBlock("constantssummary");
\r
119 $this->tpl->setVariable("ACCESS", ucfirst($access));
\r
120 $this->tpl->parseCurrentBlock();
\r
124 } // end func renderConstantSummary
\r
127 * Adds a detailed list of all constants to the template.
\r
129 * The function assumes that there is a block named "constantdetails" and
\r
130 * withing it another block named "constantdetails_loop".
\r
132 * @see renderConstantSummary()
\r
134 function renderConstantDetail() {
\r
136 reset($this->accessModifiers);
\r
137 while (list($k, $access) = each($this->accessModifiers)) {
\r
138 if (0 == count($this->constants[$access]))
\r
141 reset($this->constants[$access]);
\r
142 while (list($name, $constant) = each($this->constants[$access])) {
\r
144 $tplvars = array();
\r
145 $tplvars["NAME"] = $name;
\r
146 $tplvars["CASE"] = $constant["case"];
\r
147 $tplvars["VALUE"] = htmlentities($constant["value"]);
\r
149 if ("true" == $constant["undoc"])
\r
150 $tplvars["UNDOC"] = $this->undocumented;
\r
152 if (isset($constant["doc"]["shortdescription"]))
\r
153 $tplvars["SHORTDESCRIPTION"] = $this->encode($constant["doc"]["shortdescription"]["value"]);
\r
155 if (isset($constant["doc"]["description"]))
\r
156 $tplvars["DESCRIPTION"] = $this->encode($constant["doc"]["description"]["value"]);
\r
158 $this->renderCommonDocfields("constantdetails_", $constant);
\r
160 $this->tpl->setCurrentBlock("constantdetails_loop");
\r
161 $this->tpl->setVariable($tplvars);
\r
162 $this->tpl->parseCurrentBlock();
\r
165 $this->tpl->setCurrentBlock("constantdetails");
\r
166 $this->tpl->setVariable("ACCESS", ucfirst($access));
\r
167 $this->tpl->parseCurrentBlock();
\r
170 } // end func renderConstantsDetail
\r
173 * Adds a summary and a detailed list of included files to the template.
\r
174 * @see renderUsesSummary(), renderUsesDetail()
\r
176 function renderUses() {
\r
180 reset($this->usesTypes);
\r
181 while (list($k, $type) = each($this->usesTypes)) {
\r
183 $this->uses[$type] = $this->accessor->getUsesByType($type);
\r
184 if (!$found && 0 != count($this->uses[$type]))
\r
192 $this->renderUsesSummary();
\r
193 $this->renderUsesDetail();
\r
195 $this->uses = array();
\r
196 } // end func renderUses
\r
199 * Adds a detailed list of all included files to the template.
\r
201 * The function assumes that there is a block names "usesdetail" and within the block
\r
202 * a block names "usesdetail_loop" in the template.
\r
204 * @see renderUsesSummary()
\r
206 function renderUsesDetail() {
\r
208 reset($this->usesTypes);
\r
209 while (list($k, $type) = each($this->usesTypes)) {
\r
210 if (0 == count($this->uses[$type]))
\r
213 reset($this->uses[$type]);
\r
214 while (list($file, $uses) = each($this->uses[$type])) {
\r
216 $tplvars = array();
\r
217 $tplvars["FILE"] = $uses["file"];
\r
218 $tplvars["TYPE"] = $type;
\r
220 if ("true" == $uses["undoc"])
\r
221 $tplvars["UNDOC"] = $this->undocumented;
\r
223 if (isset($uses["doc"]["shortdescription"]))
\r
224 $tplvars["SHORTDESCRIPTION"] = $this->encode($uses["doc"]["shortdescription"]["value"]);
\r
226 if (isset($uses["doc"]["description"]))
\r
227 $tplvars["DESCRIPTION"] = $this->encode($uses["doc"]["description"]["value"]);
\r
229 $this->renderCommonDocfields("usesdetails_", $uses);
\r
230 $this->tpl->setCurrentBlock("usesdetails_loop");
\r
231 $this->tpl->setVariable($tplvars);
\r
232 $this->tpl->parseCurrentBlock();
\r
235 $this->tpl->setCurrentBlock("usesdetails");
\r
236 $this->tpl->setVariable("TYPE", $type);
\r
237 $this->tpl->parseCurrentBlock();
\r
240 } // end func renderUsesDetail
\r
243 * Adds a summary of all included files to the template.
\r
245 * The function assumes that there is a block names "usessummary" and within
\r
246 * the block another block names "usessummary_loop" in the template.
\r
248 * @see renderUsesDetail()
\r
250 function renderUsesSummary() {
\r
252 reset($this->usesTypes);
\r
253 while (list($k, $type) = each($this->usesTypes)) {
\r
254 if (0 == count($this->uses[$type]))
\r
257 $this->tpl->setCurrentBlock("usessummary_loop");
\r
259 reset($this->uses[$type]);
\r
260 while (list($file, $uses) = each($this->uses[$type])) {
\r
262 $this->tpl->setVariable("FILE", $file);
\r
263 if (isset($uses["doc"]["shortdescription"]))
\r
264 $this->tpl->setVariable("SHORTDESCRIPTION", $this->encode($uses["doc"]["shortdescription"]["value"]));
\r
266 if ("true" == $uses["undoc"])
\r
267 $this->tpl->setVariable("UNDOC", $this->undocumented);
\r
269 $this->tpl->parseCurrentBlock();
\r
272 $this->tpl->setCurrentBlock("usessummary");
\r
273 $this->tpl->setVariable("TYPE", $type);
\r
274 $this->tpl->parseCurrentBlock();
\r
277 } // end func renderUsesSummary
\r
280 * Adds a summary and a detailed list of all functions to the template.
\r
282 * @see renderFunctionSummary(), renderFunctionDetail(), $functions
\r
284 function renderFunctions() {
\r
286 $this->functions["private"] = $this->accessor->getFunctionsByAccess("private");
\r
287 $this->functions["public"] = $this->accessor->getFunctionsByAccess("public");
\r
289 if (0 == count($this->functions["private"]) && 0 == count($this->functions["public"]))
\r
292 $this->renderFunctionSummary();
\r
293 $this->renderFunctionDetail();
\r
294 $this->functions = array();
\r
296 } // end func renderFunctions
\r
299 * Adds a function summary to the template.
\r
301 * The function assumes that there is ablock names "functionsummary" and
\r
302 * within it a block names "functionsummary_loop" in the template.
\r
304 * @see renderFunctionDetail(), renderFunctions(), $functions, $accessModifiers
\r
306 function renderFunctionSummary() {
\r
308 reset($this->accessModifiers);
\r
309 while (list($k, $access) = each($this->accessModifiers)) {
\r
310 if (0 == count($this->functions[$access]))
\r
313 $this->tpl->setCurrentBlock("functionsummary_loop");
\r
314 reset($this->functions[$access]);
\r
315 while (list($name, $function) = each($this->functions[$access])) {
\r
317 $this->tpl->setVariable("NAME", $name);
\r
319 if (isset($function["doc"]["parameter"]))
\r
320 $this->tpl->setVariable("PARAMETER", $this->getParameter($function["doc"]["parameter"]));
\r
322 if (isset($function["doc"]["shortdescription"]))
\r
323 $this->tpl->setVariable("SHORTDESCRIPTION", $this->encode($function["doc"]["shortdescription"]["value"]));
\r
325 if (isset($function["doc"]["return"]))
\r
326 $this->tpl->setVariable("RETURNTYPE", $function["doc"]["return"]["type"]);
\r
328 $this->tpl->setVariable("RETURNTYPE", "void");
\r
330 if ("true" == $function["undoc"])
\r
331 $this->tpl->setVariable("UNDOC", $this->undocumented);
\r
333 $this->tpl->parseCurrentBlock();
\r
336 $this->tpl->setCurrentBlock("functionsummary");
\r
337 $this->tpl->setVariable("ACCESS", ucfirst($access) );
\r
338 $this->tpl->parseCurrentBlock();
\r
341 } // end func renderFunctionSummary
\r
344 * Adds a detailed list of functions to the template.
\r
346 * The function assumes that there is a block named "functiondetails" and
\r
347 * within it a bloc "functiondetails_loop" in the template.
\r
349 * @see renderFunctions(), renderFunctionSummary(), $functions, $accessModifiers
\r
351 function renderFunctionDetail() {
\r
353 reset($this->accessModifiers);
\r
354 while (list($k, $access) = each($this->accessModifiers)) {
\r
355 if (0 == count($this->functions[$access]))
\r
358 reset($this->functions[$access]);
\r
359 while (list($name, $function) = each($this->functions[$access])) {
\r
361 $tplvars = array();
\r
362 $tplvars["NAME"] = $function["name"];
\r
363 $tplvars["ACCESS"] = $function["access"];
\r
365 if ("true" == $function["undoc"])
\r
366 $tplvars["UNDOC"] = $this->undocumented;
\r
368 if ("true" == $function["abstract"])
\r
369 $tplvars["ABSTRACT"] = "abstract";
\r
371 if ("true" == $function["static"])
\r
372 $tplvars["STATIC"] = "static";
\r
374 if (isset($function["doc"]["shortdescription"]))
\r
375 $tplvars["SHORTDESCRIPTION"] = $this->encode($function["doc"]["shortdescription"]["value"]);
\r
377 if (isset($function["doc"]["description"]))
\r
378 $tplvars["DESCRIPTION"] = $this->encode($function["doc"]["description"]["value"]);
\r
380 $this->renderCommonDocfields("functiondetails_", $function);
\r
382 if (isset($function["doc"]["parameter"])) {
\r
383 $tplvars["PARAMETER"] = $this->getParameter($function["doc"]["parameter"]);
\r
384 $this->renderParameterDetail($function["doc"]["parameter"]);
\r
387 if (isset($function["doc"]["throws"]))
\r
388 $this->renderThrows($function["doc"]["throws"], "functiondetails_");
\r
390 if (isset($function["doc"]["global"]))
\r
391 $this->renderGlobals($function["doc"]["global"], "functiondetails_");
\r
393 if (isset($function["doc"]["return"])) {
\r
395 $tplvars["RETURNTYPE"] = $function["doc"]["return"]["type"];
\r
397 $this->tpl->setCurrentBlock("functiondetails_return");
\r
398 $this->tpl->setVariable("TYPE", $function["doc"]["return"]["type"]);
\r
399 $this->tpl->setVariable("DESCRIPTION", $this->encode($function["doc"]["return"]["value"]));
\r
401 if (isset($function["doc"]["return"]["name"]))
\r
402 $this->tpl->setVariable("NAME", $function["doc"]["return"]["name"]);
\r
404 $this->tpl->parseCurrentBlock();
\r
408 $tplvars["RETURNTYPE"] = "void";
\r
412 $this->tpl->setCurrentBlock("functiondetails_loop");
\r
413 $this->tpl->setVariable($tplvars);
\r
414 $this->tpl->parseCurrentBlock();
\r
417 $this->tpl->setCurrentBlock("functiondetails");
\r
418 $this->tpl->setVariable("ACCESS", ucfirst($access) );
\r
419 $this->tpl->parseCurrentBlock();
\r
422 } // end func renderFunctionDetail
\r
425 * Renders a detailed list of function parameters.
\r
427 * The function assumes that there is a block named "functiondetails_parameter" in
\r
428 * the template and within it a block named "functiondetails_parameter_loop".
\r
430 * @param array Parameter
\r
432 function renderParameterDetail($parameter) {
\r
434 if (!isset($parameter[0]))
\r
435 $parameter = array($parameter);
\r
437 $this->tpl->setCurrentBlock("functiondetails_parameter_loop");
\r
440 while (list($k, $param) = each($parameter)) {
\r
442 $this->tpl->setVariable("NAME", $param["name"]);
\r
443 $this->tpl->setVariable("DESCRIPTION", $this->encode($param["value"]));
\r
445 if (isset($param["type"]))
\r
446 $this->tpl->setVariable("TYPE", $param["type"]);
\r
448 if (isset($param["default"]))
\r
449 $this->tpl->setVariable("DEFAULT", "= >>".htmlentities($param["default"])."<<");
\r
451 if ("true" == $param["undoc"])
\r
452 $this->tpl->setVariable("UNDOC", $this->undocumented);
\r
454 $this->tpl->parseCurrentBlock();
\r
457 } // end func renderParameterDetail
\r
460 * Converts the XML parameter array into formatted string.
\r
462 * @param array XML parameter array
\r
463 * @return string Formatted parameter string
\r
465 function getParameter($parameter) {
\r
467 if (!is_array($parameter))
\r
472 if (!isset($parameter[0])) {
\r
474 if (!isset($parameter["default"]))
\r
475 $value .= $parameter["type"] . " " . $parameter["name"];
\r
477 $value .= "[ ".$parameter["type"] . " " . $parameter["name"]." ]";
\r
481 $flag_optional = false;
\r
484 while (list($k, $param) = each($parameter)) {
\r
486 if (!isset($param["default"])) {
\r
487 if ($flag_optional) {
\r
488 $value = substr($value, 0, -2)." ], ";
\r
489 $flag_optional = false;
\r
492 if (!$flag_optional) {
\r
494 $flag_optional = true;
\r
498 $value .= $param["type"] . " " . $param["name"].", ";
\r
501 $value = substr($value, 0, -2);
\r
502 if ($flag_optional)
\r
508 } // end func getParameter
\r
511 * Renders a block with references to other source elements.
\r
513 * @param array XML references array
\r
514 * @param string optional template blockname prefix
\r
516 function renderSee($references, $prefix = "") {
\r
519 if (!isset($references[0])) {
\r
521 if (isset($references["group"]))
\r
522 $value .= sprintf('<a href="%s#%s_%s">%s::%s</a>',
\r
523 $this->nameToUrl($references["group"]).$this->file_extension,
\r
524 $references["type"],
\r
525 $references["value"],
\r
526 $references["group"],
\r
527 $references["value"]
\r
530 $value .= sprintf('<a href="#%s_%s">%s</a>',
\r
531 $references["type"],
\r
532 $references["value"],
\r
533 $references["value"]
\r
538 reset($references);
\r
539 while (list($k, $reference) = each($references)) {
\r
541 if (isset($reference["group"]))
\r
542 $value .= sprintf('<a href="%s#%s_%s">%s::%s</a>, ',
\r
543 $this->nameToUrl($reference["group"]).$this->file_extension,
\r
544 $reference["type"],
\r
545 $reference["value"],
\r
546 $reference["group"],
\r
547 $reference["value"]
\r
550 $value .= sprintf('<a href="#%s_%s">%s</a>, ',
\r
551 $reference["type"],
\r
552 $reference["value"],
\r
553 $reference["value"]
\r
558 $value = substr($value, 0, -2);
\r
561 $this->tpl->setCurrentBlock(strtolower($prefix) . "see");
\r
562 $this->tpl->setVariable("SEE", $value);
\r
563 $this->tpl->parseCurrentBlock();
\r
565 } // end func renderSee
\r
568 * Renders an author list.
\r
570 * @param array XML author array
\r
571 * @param string optional template blockname prefix
\r
573 function renderAuthors($authors, $prefix = "") {
\r
577 if (!isset($authors[0])) {
\r
579 if (isset($authors["email"]))
\r
580 $value .= sprintf('%s <<a href="mailto:%s">%s</a>>, ', $authors["value"], $authors["email"], $authors["email"]);
\r
582 $value .= $authors["email"] . ", ";
\r
587 while (list($k, $author) = each($authors)) {
\r
589 if (isset($author["email"]))
\r
590 $value .= sprintf('%s <<a href="mailto:%s">%s</a>>, ', $author["value"], $author["email"], $author["email"]);
\r
592 $value .= $author["email"] . ", ";
\r
598 $value = substr($value, 0, -2);
\r
599 $this->tpl->setCurrentBlock(strtolower($prefix) . "authors");
\r
600 $this->tpl->setVariable("AUTHOR", $value);
\r
601 $this->tpl->parseCurrentBlock();
\r
603 } // end func renderAuthors
\r
606 * Renders a list of external links.
\r
608 * @param array XML link array
\r
609 * @param string optional template blockname prefix
\r
611 function renderLinks($links, $prefix = "") {
\r
614 if (!isset($links[0])) {
\r
615 $value .= sprintf('<a href="%s">%s</a>%s, ',
\r
618 ("" != $links["description"]) ? " - " . $links["description"] : ""
\r
623 while (list($k, $link) = each($links)) {
\r
624 $value .= sprintf('<a href="%s">%s</a>%s, ',
\r
627 ("" != $link["description"]) ? " - " . $links["description"] : ""
\r
633 $value = substr($value, 0, 2);
\r
634 $this->tpl->setCurrentBlock(strtolower($prefix) . "links");
\r
635 $this->tpl->setVariable("LINK", $value);
\r
636 $this->tpl->parseCurrentBlock();
\r
638 } // end func renderLinks
\r
641 * Renders a list of exceptions.
\r
643 * @param array XML array
\r
644 * @param string optional template blockname prefix
\r
646 function renderThrows($throws, $prefix = "") {
\r
649 if (!isset($throws[0])) {
\r
651 $value = $throws["value"];
\r
656 while (list($k, $exception) = each($throws))
\r
657 $value .= sprintf("%s, ", $exception["value"]);
\r
659 $value = substr($value, 0, -2);
\r
663 $this->tpl->setCurrentBlock(strtolower($prefix) . "throws");
\r
664 $this->tpl->setVariable("EXCEPTIONS", $value);
\r
665 $this->tpl->parseCurrentBlock();
\r
667 } // end func renderThrows
\r
670 * Renders a list of global elements.
\r
672 * @param array XML globals array
\r
673 * @param string optional template blockname prefix
\r
675 function renderGlobals($globals, $prefix = "") {
\r
677 $prefix = strtolower($prefix);
\r
678 $this->tpl->setCurrentBlock($prefix . "globals_loop");
\r
680 if (!isset($globals[0])) {
\r
682 $this->tpl->setVariable("NAME", $globals["name"]);
\r
683 $this->tpl->setVariable("DESCRIPTION", $this->encode($globals["value"]));
\r
685 if (isset($globals["type"]))
\r
686 $this->tpl->setVariable("TYPE", $globals["type"]);
\r
688 $this->tpl->parseCurrentBlock();
\r
693 while (list($k, $global) = each($globals)) {
\r
695 $this->tpl->setVariable("NAME", $global["name"]);
\r
696 $this->tpl->setVariable("DESCRIPTION", $this->encode($global["value"]));
\r
698 if (isset($globals["type"]))
\r
699 $this->tpl->setVariable("TYPE", $globals["type"]);
\r
701 $this->tpl->parseCurrentBlock();
\r
707 } // end func renderGlobals
\r
710 * Adds some tags to the template that are allowed nearly everywhere.
\r
712 * @param string template blockname prefixs
\r
714 * @see $simpleDocfields, renderLinks(), renderAuthors(), renderSee()
\r
716 function renderCommonDocfields($block, &$data) {
\r
718 reset($this->simpleDocfields);
\r
719 while (list($varname, $field) = each($this->simpleDocfields)) {
\r
721 if (isset($data["doc"][$field])) {
\r
723 $this->tpl->setCurrentBlock($block.$field);
\r
724 $this->tpl->setVariable($varname, htmlentities($data["doc"][$field]["value"]));
\r
725 $this->tpl->parseCurrentBlock();
\r
731 if (isset($data["doc"]["link"]))
\r
732 $this->renderLinks($data["doc"]["link"], $block);
\r
734 if (isset($data["doc"]["author"]))
\r
735 $this->renderAuthors($data["doc"]["author"], $block);
\r
737 if (isset($data["doc"]["see"]))
\r
738 $this->renderSee($data["doc"]["see"], $block);
\r
740 } // end func renderCommonDocfields
\r
742 } // end func PhpdocHTMLDocumentRenderer
\r