/xampp/php/PEAR/PHPDoc/renderer/html/PhpdocHTMLDocumentRenderer.php

https://github.com/edmondscommerce/XAMPP-Magento-Demo-Site · PHP · 744 lines · 402 code · 185 blank · 157 comment · 118 complexity · 8cf4cc28b801e6b1590fc2bf2337777d MD5 · raw file

  1. <?php
  2. /**
  3. * Provides functioninality to render modules and classes.
  4. *
  5. * @version $Id: PhpdocHTMLDocumentRenderer.php,v 1.3 2001/12/13 10:34:13 hayk Exp $
  6. */
  7. class PhpdocHTMLDocumentRenderer extends PhpdocHTMLRenderer {
  8. /**
  9. * Message displayed if an object lacks documentation.
  10. *
  11. * @var string $undocumented
  12. * @access public
  13. */
  14. var $undocumented = "Warning: documentation is missing.";
  15. /**
  16. * Array of functions found in the xml document.
  17. *
  18. * @var array $functions
  19. */
  20. var $functions = array();
  21. /**
  22. * Array of included files.
  23. *
  24. * @var array $uses
  25. */
  26. var $uses = array();
  27. /**
  28. * Array of constants.
  29. *
  30. * @var array $constants
  31. */
  32. var $constants = array();
  33. /**
  34. * Array of access modifiers.
  35. *
  36. * @var array $accessModifiers
  37. */
  38. var $accessModifiers = array("public", "private");
  39. /**
  40. * Array of doc container fields that get mapped directly to templateblocks.
  41. *
  42. * @var array $simpleDocfields
  43. * @see renderVariableDetail()
  44. */
  45. var $simpleDocfields = array(
  46. "VERSION" => "version",
  47. "SINCE" => "since",
  48. "DEPRECATED" => "deprecated",
  49. "COPYRIGHT" => "copyright",
  50. "MAGIC" => "magic"
  51. );
  52. /**
  53. * Types of include statements.
  54. *
  55. * @var array $usesTypes
  56. * @see renderUses()
  57. */
  58. var $usesTypes = array( "include", "include_once", "require", "require_once" );
  59. /**
  60. * Adds a summary and a detailed list of all constants to the template.
  61. *
  62. * @see renderConstantSummary(), renderConstantDetail()
  63. */
  64. function renderConstants() {
  65. $this->constants["public"] = $this->accessor->getConstantsByAccess("public");
  66. $this->constants["private"] = $this->accessor->getConstantsByAccess("private");
  67. if (0 == count($this->constants["public"]) && 0 == count($this->constants["private"]))
  68. return;
  69. $this->renderConstantSummary();
  70. $this->renderConstantDetail();
  71. $this->constants = array();
  72. } // end func renderConstants
  73. /**
  74. * Adds a summary of all constants to the template.
  75. *
  76. * The function assumes that there is a block called "constantssummary" and
  77. * withing this block a bock called "constantssummary_loop" in the template.
  78. *
  79. * @see renderConstantDetail()
  80. */
  81. function renderConstantSummary() {
  82. reset($this->accessModifiers);
  83. while (list($k, $access) = each($this->accessModifiers)) {
  84. if (0 == count($this->constants[$access]))
  85. continue;
  86. $this->tpl->setCurrentBlock("constantssummary_loop");
  87. reset($this->constants[$access]);
  88. while (list($name, $const) = each($this->constants[$access])) {
  89. $this->tpl->setVariable("NAME", $name);
  90. $this->tpl->setVariable("VALUE", htmlentities($const["value"]));
  91. if (isset($const["doc"]["shortdescription"]))
  92. $this->tpl->setVariable("SHORTDESCRIPTION", $this->encode($const["doc"]["shortdescription"]["value"]));
  93. if ("true" == $const["undoc"])
  94. $this->tpl->setVariable("UNDOC", $this->undocumented);
  95. $this->tpl->parseCurrentBlock();
  96. }
  97. $this->tpl->setCurrentBlock("constantssummary");
  98. $this->tpl->setVariable("ACCESS", ucfirst($access));
  99. $this->tpl->parseCurrentBlock();
  100. }
  101. } // end func renderConstantSummary
  102. /**
  103. * Adds a detailed list of all constants to the template.
  104. *
  105. * The function assumes that there is a block named "constantdetails" and
  106. * withing it another block named "constantdetails_loop".
  107. *
  108. * @see renderConstantSummary()
  109. */
  110. function renderConstantDetail() {
  111. reset($this->accessModifiers);
  112. while (list($k, $access) = each($this->accessModifiers)) {
  113. if (0 == count($this->constants[$access]))
  114. continue;
  115. reset($this->constants[$access]);
  116. while (list($name, $constant) = each($this->constants[$access])) {
  117. $tplvars = array();
  118. $tplvars["NAME"] = $name;
  119. $tplvars["CASE"] = $constant["case"];
  120. $tplvars["VALUE"] = htmlentities($constant["value"]);
  121. if ("true" == $constant["undoc"])
  122. $tplvars["UNDOC"] = $this->undocumented;
  123. if (isset($constant["doc"]["shortdescription"]))
  124. $tplvars["SHORTDESCRIPTION"] = $this->encode($constant["doc"]["shortdescription"]["value"]);
  125. if (isset($constant["doc"]["description"]))
  126. $tplvars["DESCRIPTION"] = $this->encode($constant["doc"]["description"]["value"]);
  127. $this->renderCommonDocfields("constantdetails_", $constant);
  128. $this->tpl->setCurrentBlock("constantdetails_loop");
  129. $this->tpl->setVariable($tplvars);
  130. $this->tpl->parseCurrentBlock();
  131. }
  132. $this->tpl->setCurrentBlock("constantdetails");
  133. $this->tpl->setVariable("ACCESS", ucfirst($access));
  134. $this->tpl->parseCurrentBlock();
  135. }
  136. } // end func renderConstantsDetail
  137. /**
  138. * Adds a summary and a detailed list of included files to the template.
  139. *
  140. * @see renderUsesSummary(), renderUsesDetail()
  141. */
  142. function renderUses() {
  143. $found = false;
  144. reset($this->usesTypes);
  145. while (list($k, $type) = each($this->usesTypes)) {
  146. $this->uses[$type] = $this->accessor->getUsesByType($type);
  147. if (!$found && 0 != count($this->uses[$type]))
  148. $found = true;
  149. }
  150. if (!$found)
  151. return;
  152. $this->renderUsesSummary();
  153. $this->renderUsesDetail();
  154. $this->uses = array();
  155. } // end func renderUses
  156. /**
  157. * Adds a detailed list of all included files to the template.
  158. *
  159. * The function assumes that there is a block names "usesdetail" and within the block
  160. * a block names "usesdetail_loop" in the template.
  161. *
  162. * @see renderUsesSummary()
  163. */
  164. function renderUsesDetail() {
  165. reset($this->usesTypes);
  166. while (list($k, $type) = each($this->usesTypes)) {
  167. if (0 == count($this->uses[$type]))
  168. continue;
  169. reset($this->uses[$type]);
  170. while (list($file, $uses) = each($this->uses[$type])) {
  171. $tplvars = array();
  172. $tplvars["FILE"] = $uses["file"];
  173. $tplvars["TYPE"] = $type;
  174. if ("true" == $uses["undoc"])
  175. $tplvars["UNDOC"] = $this->undocumented;
  176. if (isset($uses["doc"]["shortdescription"]))
  177. $tplvars["SHORTDESCRIPTION"] = $this->encode($uses["doc"]["shortdescription"]["value"]);
  178. if (isset($uses["doc"]["description"]))
  179. $tplvars["DESCRIPTION"] = $this->encode($uses["doc"]["description"]["value"]);
  180. $this->renderCommonDocfields("usesdetails_", $uses);
  181. $this->tpl->setCurrentBlock("usesdetails_loop");
  182. $this->tpl->setVariable($tplvars);
  183. $this->tpl->parseCurrentBlock();
  184. }
  185. $this->tpl->setCurrentBlock("usesdetails");
  186. $this->tpl->setVariable("TYPE", $type);
  187. $this->tpl->parseCurrentBlock();
  188. }
  189. } // end func renderUsesDetail
  190. /**
  191. * Adds a summary of all included files to the template.
  192. *
  193. * The function assumes that there is a block names "usessummary" and within
  194. * the block another block names "usessummary_loop" in the template.
  195. *
  196. * @see renderUsesDetail()
  197. */
  198. function renderUsesSummary() {
  199. reset($this->usesTypes);
  200. while (list($k, $type) = each($this->usesTypes)) {
  201. if (0 == count($this->uses[$type]))
  202. continue;
  203. $this->tpl->setCurrentBlock("usessummary_loop");
  204. reset($this->uses[$type]);
  205. while (list($file, $uses) = each($this->uses[$type])) {
  206. $this->tpl->setVariable("FILE", $file);
  207. if (isset($uses["doc"]["shortdescription"]))
  208. $this->tpl->setVariable("SHORTDESCRIPTION", $this->encode($uses["doc"]["shortdescription"]["value"]));
  209. if ("true" == $uses["undoc"])
  210. $this->tpl->setVariable("UNDOC", $this->undocumented);
  211. $this->tpl->parseCurrentBlock();
  212. }
  213. $this->tpl->setCurrentBlock("usessummary");
  214. $this->tpl->setVariable("TYPE", $type);
  215. $this->tpl->parseCurrentBlock();
  216. }
  217. } // end func renderUsesSummary
  218. /**
  219. * Adds a summary and a detailed list of all functions to the template.
  220. *
  221. * @see renderFunctionSummary(), renderFunctionDetail(), $functions
  222. */
  223. function renderFunctions() {
  224. $this->functions["private"] = $this->accessor->getFunctionsByAccess("private");
  225. $this->functions["public"] = $this->accessor->getFunctionsByAccess("public");
  226. if (0 == count($this->functions["private"]) && 0 == count($this->functions["public"]))
  227. return;
  228. $this->renderFunctionSummary();
  229. $this->renderFunctionDetail();
  230. $this->functions = array();
  231. } // end func renderFunctions
  232. /**
  233. * Adds a function summary to the template.
  234. *
  235. * The function assumes that there is ablock names "functionsummary" and
  236. * within it a block names "functionsummary_loop" in the template.
  237. *
  238. * @see renderFunctionDetail(), renderFunctions(), $functions, $accessModifiers
  239. */
  240. function renderFunctionSummary() {
  241. reset($this->accessModifiers);
  242. while (list($k, $access) = each($this->accessModifiers)) {
  243. if (0 == count($this->functions[$access]))
  244. continue;
  245. $this->tpl->setCurrentBlock("functionsummary_loop");
  246. reset($this->functions[$access]);
  247. while (list($name, $function) = each($this->functions[$access])) {
  248. $this->tpl->setVariable("NAME", $name);
  249. if (isset($function["doc"]["parameter"]))
  250. $this->tpl->setVariable("PARAMETER", $this->getParameter($function["doc"]["parameter"]));
  251. if (isset($function["doc"]["shortdescription"]))
  252. $this->tpl->setVariable("SHORTDESCRIPTION", $this->encode($function["doc"]["shortdescription"]["value"]));
  253. if (isset($function["doc"]["return"]))
  254. $this->tpl->setVariable("RETURNTYPE", $function["doc"]["return"]["type"]);
  255. else
  256. $this->tpl->setVariable("RETURNTYPE", "void");
  257. if ("true" == $function["undoc"])
  258. $this->tpl->setVariable("UNDOC", $this->undocumented);
  259. $this->tpl->parseCurrentBlock();
  260. }
  261. $this->tpl->setCurrentBlock("functionsummary");
  262. $this->tpl->setVariable("ACCESS", ucfirst($access) );
  263. $this->tpl->parseCurrentBlock();
  264. }
  265. } // end func renderFunctionSummary
  266. /**
  267. * Adds a detailed list of functions to the template.
  268. *
  269. * The function assumes that there is a block named "functiondetails" and
  270. * within it a bloc "functiondetails_loop" in the template.
  271. *
  272. * @see renderFunctions(), renderFunctionSummary(), $functions, $accessModifiers
  273. */
  274. function renderFunctionDetail() {
  275. reset($this->accessModifiers);
  276. while (list($k, $access) = each($this->accessModifiers)) {
  277. if (0 == count($this->functions[$access]))
  278. continue;
  279. reset($this->functions[$access]);
  280. while (list($name, $function) = each($this->functions[$access])) {
  281. $tplvars = array();
  282. $tplvars["NAME"] = $function["name"];
  283. $tplvars["ACCESS"] = $function["access"];
  284. if ("true" == $function["undoc"])
  285. $tplvars["UNDOC"] = $this->undocumented;
  286. if ("true" == $function["abstract"])
  287. $tplvars["ABSTRACT"] = "abstract";
  288. if ("true" == $function["static"])
  289. $tplvars["STATIC"] = "static";
  290. if (isset($function["doc"]["shortdescription"]))
  291. $tplvars["SHORTDESCRIPTION"] = $this->encode($function["doc"]["shortdescription"]["value"]);
  292. if (isset($function["doc"]["description"]))
  293. $tplvars["DESCRIPTION"] = $this->encode($function["doc"]["description"]["value"]);
  294. $this->renderCommonDocfields("functiondetails_", $function);
  295. if (isset($function["doc"]["parameter"])) {
  296. $tplvars["PARAMETER"] = $this->getParameter($function["doc"]["parameter"]);
  297. $this->renderParameterDetail($function["doc"]["parameter"]);
  298. }
  299. if (isset($function["doc"]["throws"]))
  300. $this->renderThrows($function["doc"]["throws"], "functiondetails_");
  301. if (isset($function["doc"]["global"]))
  302. $this->renderGlobals($function["doc"]["global"], "functiondetails_");
  303. if (isset($function["doc"]["return"])) {
  304. $tplvars["RETURNTYPE"] = $function["doc"]["return"]["type"];
  305. $this->tpl->setCurrentBlock("functiondetails_return");
  306. $this->tpl->setVariable("TYPE", $function["doc"]["return"]["type"]);
  307. $this->tpl->setVariable("DESCRIPTION", $this->encode($function["doc"]["return"]["value"]));
  308. if (isset($function["doc"]["return"]["name"]))
  309. $this->tpl->setVariable("NAME", $function["doc"]["return"]["name"]);
  310. $this->tpl->parseCurrentBlock();
  311. } else {
  312. $tplvars["RETURNTYPE"] = "void";
  313. }
  314. $this->tpl->setCurrentBlock("functiondetails_loop");
  315. $this->tpl->setVariable($tplvars);
  316. $this->tpl->parseCurrentBlock();
  317. }
  318. $this->tpl->setCurrentBlock("functiondetails");
  319. $this->tpl->setVariable("ACCESS", ucfirst($access) );
  320. $this->tpl->parseCurrentBlock();
  321. }
  322. } // end func renderFunctionDetail
  323. /**
  324. * Renders a detailed list of function parameters.
  325. *
  326. * The function assumes that there is a block named "functiondetails_parameter" in
  327. * the template and within it a block named "functiondetails_parameter_loop".
  328. *
  329. * @param array Parameter
  330. */
  331. function renderParameterDetail($parameter) {
  332. if (!isset($parameter[0]))
  333. $parameter = array($parameter);
  334. $this->tpl->setCurrentBlock("functiondetails_parameter_loop");
  335. reset($parameter);
  336. while (list($k, $param) = each($parameter)) {
  337. $this->tpl->setVariable("NAME", $param["name"]);
  338. $this->tpl->setVariable("DESCRIPTION", $this->encode($param["value"]));
  339. if (isset($param["type"]))
  340. $this->tpl->setVariable("TYPE", $param["type"]);
  341. if (isset($param["default"]))
  342. $this->tpl->setVariable("DEFAULT", "= >>".htmlentities($param["default"])."<<");
  343. if ("true" == $param["undoc"])
  344. $this->tpl->setVariable("UNDOC", $this->undocumented);
  345. $this->tpl->parseCurrentBlock();
  346. }
  347. } // end func renderParameterDetail
  348. /**
  349. * Converts the XML parameter array into formatted string.
  350. *
  351. * @param array XML parameter array
  352. * @return string Formatted parameter string
  353. */
  354. function getParameter($parameter) {
  355. if (!is_array($parameter))
  356. return "void";
  357. $value = "";
  358. if (!isset($parameter[0])) {
  359. if (!isset($parameter["default"]))
  360. $value .= $parameter["type"] . " " . $parameter["name"];
  361. else
  362. $value .= "[ ".$parameter["type"] . " " . $parameter["name"]." ]";
  363. } else {
  364. $flag_optional = false;
  365. reset($parameter);
  366. while (list($k, $param) = each($parameter)) {
  367. if (!isset($param["default"])) {
  368. if ($flag_optional) {
  369. $value = substr($value, 0, -2) . " ], ";
  370. $flag_optional = false;
  371. }
  372. } else {
  373. if (!$flag_optional) {
  374. $value .= "[ ";
  375. $flag_optional = true;
  376. }
  377. }
  378. $value .= $param["type"] . " " . $param["name"].", ";
  379. }
  380. $value = substr($value, 0, -2);
  381. if ($flag_optional)
  382. $value .= " ]";
  383. }
  384. return $value;
  385. } // end func getParameter
  386. /**
  387. * Renders a block with references to other source elements.
  388. *
  389. * @param array XML references array
  390. * @param string optional template blockname prefix
  391. */
  392. function renderSee($references, $prefix = "") {
  393. $value = "";
  394. if (!isset($references[0])) {
  395. if (isset($references["group"]))
  396. $value .= sprintf('<a href="%s#%s_%s">%s::%s</a>',
  397. $this->nameToUrl($references["group"]).$this->file_extension,
  398. $references["type"],
  399. $references["value"],
  400. $references["group"],
  401. $references["value"]
  402. );
  403. else
  404. $value .= sprintf('<a href="#%s_%s">%s</a>',
  405. $references["type"],
  406. $references["value"],
  407. $references["value"]
  408. );
  409. } else {
  410. reset($references);
  411. while (list($k, $reference) = each($references)) {
  412. if (isset($reference["group"]))
  413. $value .= sprintf('<a href="%s#%s_%s">%s::%s</a>, ',
  414. $this->nameToUrl($reference["group"]).$this->file_extension,
  415. $reference["type"],
  416. $reference["value"],
  417. $reference["group"],
  418. $reference["value"]
  419. );
  420. else
  421. $value .= sprintf('<a href="#%s_%s">%s</a>, ',
  422. $reference["type"],
  423. $reference["value"],
  424. $reference["value"]
  425. );
  426. }
  427. $value = substr($value, 0, -2);
  428. }
  429. $this->tpl->setCurrentBlock(strtolower($prefix) . "see");
  430. $this->tpl->setVariable("SEE", $value);
  431. $this->tpl->parseCurrentBlock();
  432. } // end func renderSee
  433. /**
  434. * Renders an author list.
  435. *
  436. * @param array XML author array
  437. * @param string optional template blockname prefix
  438. */
  439. function renderAuthors($authors, $prefix = "") {
  440. $value = "";
  441. if (!isset($authors[0])) {
  442. if (isset($authors["email"]))
  443. $value .= sprintf('%s &lt;<a href="mailto:%s">%s</a>&gt;, ', $authors["value"], $authors["email"], $authors["email"]);
  444. else
  445. $value .= $authors["email"] . ", ";
  446. } else {
  447. reset($authors);
  448. while (list($k, $author) = each($authors)) {
  449. if (isset($author["email"]))
  450. $value .= sprintf('%s &lt;<a href="mailto:%s">%s</a>&gt;, ', $author["value"], $author["email"], $author["email"]);
  451. else
  452. $value .= $author["email"] . ", ";
  453. }
  454. }
  455. $value = substr($value, 0, -2);
  456. $this->tpl->setCurrentBlock(strtolower($prefix) . "authors");
  457. $this->tpl->setVariable("AUTHOR", $value);
  458. $this->tpl->parseCurrentBlock();
  459. } // end func renderAuthors
  460. /**
  461. * Renders a list of external links.
  462. *
  463. * @param array XML link array
  464. * @param string optional template blockname prefix
  465. */
  466. function renderLinks($links, $prefix = "") {
  467. $value = "";
  468. if (!isset($links[0])) {
  469. $value .= sprintf('<a href="%s" target="_blank">%s</a>%s, ',
  470. $links["url"],
  471. $links["url"],
  472. ("" != $links["value"]) ? " - " . $links["value"] : ""
  473. );
  474. } else {
  475. reset($links);
  476. while (list($k, $link) = each($links)) {
  477. $value .= sprintf('<a href="%s" target="_blank">%s</a>%s, ',
  478. $link["url"],
  479. $link["url"],
  480. ("" != $link["value"]) ? " - " . $links["value"] : ""
  481. );
  482. }
  483. }
  484. $value = substr($value, 0, -2);
  485. $this->tpl->setCurrentBlock(strtolower($prefix) . "links");
  486. $this->tpl->setVariable("LINK", $value);
  487. $this->tpl->parseCurrentBlock();
  488. } // end func renderLinks
  489. /**
  490. * Renders a list of exceptions.
  491. *
  492. * @param array XML array
  493. * @param string optional template blockname prefix
  494. */
  495. function renderThrows($throws, $prefix = "") {
  496. $value = "";
  497. if (!isset($throws[0])) {
  498. $value = $throws["value"];
  499. } else {
  500. reset($throws);
  501. while (list($k, $exception) = each($throws))
  502. $value .= sprintf("%s, ", $exception["value"]);
  503. $value = substr($value, 0, -2);
  504. }
  505. $this->tpl->setCurrentBlock(strtolower($prefix) . "throws");
  506. $this->tpl->setVariable("EXCEPTIONS", $value);
  507. $this->tpl->parseCurrentBlock();
  508. } // end func renderThrows
  509. /**
  510. * Renders a list of global elements.
  511. *
  512. * @param array XML globals array
  513. * @param string optional template blockname prefix
  514. */
  515. function renderGlobals($globals, $prefix = "") {
  516. $prefix = strtolower($prefix);
  517. $this->tpl->setCurrentBlock($prefix . "globals_loop");
  518. if (!isset($globals[0])) {
  519. $this->tpl->setVariable("NAME", $globals["name"]);
  520. $this->tpl->setVariable("DESCRIPTION", $this->encode($globals["value"]));
  521. if (isset($globals["type"]))
  522. $this->tpl->setVariable("TYPE", $globals["type"]);
  523. $this->tpl->parseCurrentBlock();
  524. } else {
  525. reset($globals);
  526. while (list($k, $global) = each($globals)) {
  527. $this->tpl->setVariable("NAME", $global["name"]);
  528. $this->tpl->setVariable("DESCRIPTION", $this->encode($global["value"]));
  529. if (isset($globals["type"]))
  530. $this->tpl->setVariable("TYPE", $globals["type"]);
  531. $this->tpl->parseCurrentBlock();
  532. }
  533. }
  534. } // end func renderGlobals
  535. /**
  536. * Adds some tags to the template that are allowed nearly everywhere.
  537. *
  538. * @param string template blockname prefixs
  539. * @param array
  540. * @see $simpleDocfields, renderLinks(), renderAuthors(), renderSee()
  541. */
  542. function renderCommonDocfields($block, &$data) {
  543. reset($this->simpleDocfields);
  544. while (list($varname, $field) = each($this->simpleDocfields)) {
  545. if (isset($data["doc"][$field])) {
  546. $this->tpl->setCurrentBlock($block.$field);
  547. $this->tpl->setVariable($varname, htmlentities($data["doc"][$field]["value"]));
  548. $this->tpl->parseCurrentBlock();
  549. }
  550. }
  551. if (isset($data["doc"]["link"]))
  552. $this->renderLinks($data["doc"]["link"], $block);
  553. if (isset($data["doc"]["author"]))
  554. $this->renderAuthors($data["doc"]["author"], $block);
  555. if (isset($data["doc"]["see"]))
  556. $this->renderSee($data["doc"]["see"], $block);
  557. } // end func renderCommonDocfields
  558. } // end func PhpdocHTMLDocumentRenderer
  559. ?>