PageRenderTime 26ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/doclets/standard/packageWriter.php

http://github.com/peej/phpdoctor
PHP | 291 lines | 202 code | 47 blank | 42 comment | 28 complexity | 4e47097a3d33f476a41020fef47e9bc3 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. PHPDoctor: The PHP Documentation Creator
  4. Copyright (C) 2004 Paul James <paul@peej.co.uk>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. /** This generates the package-summary.html files that list the interfaces and
  18. * classes for a given package.
  19. *
  20. * @package PHPDoctor\Doclets\Standard
  21. */
  22. class packageWriter extends HTMLWriter
  23. {
  24. /** Build the package summaries.
  25. *
  26. * @param Doclet doclet
  27. */
  28. public function packageWriter(&$doclet)
  29. {
  30. parent::HTMLWriter($doclet);
  31. $rootDoc =& $this->_doclet->rootDoc();
  32. $phpdoctor =& $this->_doclet->phpdoctor();
  33. $displayTree = $phpdoctor->getOption('tree');
  34. if ($displayTree) {
  35. $this->_sections[0] = array('title' => 'Overview', 'url' => 'overview-summary.html');
  36. $this->_sections[1] = array('title' => 'Namespace');
  37. $this->_sections[2] = array('title' => 'Class');
  38. //$this->_sections[3] = array('title' => 'Use');
  39. $this->_sections[4] = array('title' => 'Tree', 'selected' => TRUE);
  40. if ($doclet->includeSource()) $this->_sections[5] = array('title' => 'Files', 'url' => 'overview-files.html');
  41. $this->_sections[6] = array('title' => 'Deprecated', 'url' => 'deprecated-list.html');
  42. $this->_sections[7] = array('title' => 'Todo', 'url' => 'todo-list.html');
  43. $this->_sections[8] = array('title' => 'Index', 'url' => 'index-all.html');
  44. $this->_id = 'tree';
  45. $tree = array();
  46. $classes =& $rootDoc->classes();
  47. if ($classes) {
  48. foreach ($classes as $class) {
  49. $this->_buildTree($tree, $class);
  50. }
  51. }
  52. ob_start();
  53. echo "<hr>\n\n";
  54. echo '<h1>Class Hierarchy</h1>';
  55. $this->_displayTree($tree);
  56. $this->_output = ob_get_contents();
  57. ob_end_clean();
  58. $this->_write('overview-tree.html', 'Overview', TRUE);
  59. }
  60. $this->_id = 'package';
  61. $packages =& $rootDoc->packages();
  62. ksort($packages);
  63. foreach ($packages as $packageName => $package) {
  64. $this->_depth = $package->depth() + 1;
  65. $this->_sections[0] = array('title' => 'Overview', 'url' => 'overview-summary.html');
  66. $this->_sections[1] = array('title' => 'Namespace', 'selected' => TRUE);
  67. $this->_sections[2] = array('title' => 'Class');
  68. //$this->_sections[3] = array('title' => 'Use');
  69. if ($displayTree) $this->_sections[4] = array('title' => 'Tree', 'url' => $package->asPath().'/package-tree.html');
  70. if ($doclet->includeSource()) $this->_sections[5] = array('title' => 'Files', 'url' => 'overview-files.html');
  71. $this->_sections[6] = array('title' => 'Deprecated', 'url' => 'deprecated-list.html');
  72. $this->_sections[7] = array('title' => 'Todo', 'url' => 'todo-list.html');
  73. $this->_sections[8] = array('title' => 'Index', 'url' => 'index-all.html');
  74. ob_start();
  75. echo "<hr>\n\n";
  76. echo '<h1>Namespace ', $package->name(), "</h1>\n\n";
  77. $textTag =& $package->tags('@text');
  78. if ($textTag) {
  79. echo '<div class="comment">', $this->_processInlineTags($textTag, TRUE), "</div>\n\n";
  80. echo '<dl><dt>See:</dt><dd><b><a href="#overview_description">Description</a></b></dd></dl>', "\n\n";
  81. }
  82. $classes =& $package->ordinaryClasses();
  83. if ($classes) {
  84. ksort($classes);
  85. echo '<table class="title">', "\n";
  86. echo '<tr><th colspan="2" class="title">Class Summary</th></tr>', "\n";
  87. foreach ($classes as $name => $class) {
  88. $textTag =& $classes[$name]->tags('@text');
  89. echo '<tr><td class="name"><a href="', str_repeat('../', $this->_depth), $classes[$name]->asPath(), '">', $classes[$name]->name(), '</a></td>';
  90. echo '<td class="description">';
  91. if ($textTag) echo strip_tags($this->_processInlineTags($textTag, TRUE), '<a><b><strong><u><em>');
  92. echo "</td></tr>\n";
  93. }
  94. echo "</table>\n\n";
  95. }
  96. $interfaces =& $package->interfaces();
  97. if ($interfaces) {
  98. ksort($interfaces);
  99. echo '<table class="title">'."\n";
  100. echo '<tr><th colspan="2" class="title">Interface Summary</th></tr>'."\n";
  101. foreach ($interfaces as $name => $interface) {
  102. $textTag =& $interfaces[$name]->tags('@text');
  103. echo '<tr><td class="name"><a href="', str_repeat('../', $this->_depth), $interfaces[$name]->asPath(), '">', $interfaces[$name]->name(), '</a></td>';
  104. echo '<td class="description">';
  105. if ($textTag) echo strip_tags($this->_processInlineTags($textTag, TRUE), '<a><b><strong><u><em>');
  106. echo "</td></tr>\n";
  107. }
  108. echo "</table>\n\n";
  109. }
  110. $traits =& $package->traits();
  111. if ($traits) {
  112. ksort($traits);
  113. echo '<table class="title">'."\n";
  114. echo '<tr><th colspan="2" class="title">Trait Summary</th></tr>'."\n";
  115. foreach ($traits as $name => $trait) {
  116. $textTag =& $traits[$name]->tags('@text');
  117. echo '<tr><td class="name"><a href="', str_repeat('../', $this->_depth), $traits[$name]->asPath(), '">', $traits[$name]->name(), '</a></td>';
  118. echo '<td class="description">';
  119. if ($textTag) echo strip_tags($this->_processInlineTags($textTag, TRUE), '<a><b><strong><u><em>');
  120. echo "</td></tr>\n";
  121. }
  122. echo "</table>\n\n";
  123. }
  124. $exceptions =& $package->exceptions();
  125. if ($exceptions) {
  126. ksort($exceptions);
  127. echo '<table class="title">'."\n";
  128. echo '<tr><th colspan="2" class="title">Exception Summary</th></tr>'."\n";
  129. foreach ($exceptions as $name => $exception) {
  130. $textTag =& $exceptions[$name]->tags('@text');
  131. echo '<tr><td class="name"><a href="', str_repeat('../', $this->_depth), $exceptions[$name]->asPath(), '">', $exceptions[$name]->name(), '</a></td>';
  132. echo '<td class="description">';
  133. if ($textTag) echo strip_tags($this->_processInlineTags($textTag, TRUE), '<a><b><strong><u><em>');
  134. echo "</td></tr>\n";
  135. }
  136. echo "</table>\n\n";
  137. }
  138. $functions =& $package->functions();
  139. if ($functions) {
  140. ksort($functions);
  141. echo '<table class="title">', "\n";
  142. echo '<tr><th colspan="2" class="title">Function Summary</th></tr>', "\n";
  143. foreach ($functions as $name => $function) {
  144. $textTag =& $functions[$name]->tags('@text');
  145. echo '<tr><td class="name"><a href="package-functions.html#', $functions[$name]->name(), '">', $functions[$name]->name(), '</a></td>';
  146. echo '<td class="description">';
  147. if ($textTag) echo strip_tags($this->_processInlineTags($textTag, TRUE), '<a><b><strong><u><em>');
  148. echo "</td></tr>\n";
  149. }
  150. echo "</table>\n\n";
  151. }
  152. $globals =& $package->globals();
  153. if ($globals) {
  154. ksort($globals);
  155. echo '<table class="title">', "\n";
  156. echo '<tr><th colspan="2" class="title">Global Summary</th></tr>', "\n";
  157. foreach ($globals as $name => $global) {
  158. $textTag =& $globals[$name]->tags('@text');
  159. echo '<tr><td class="name"><a href="package-globals.html#', $globals[$name]->name(), '">', $globals[$name]->name(), '</a></td>';
  160. echo '<td class="description">';
  161. if ($textTag) echo strip_tags($this->_processInlineTags($textTag, TRUE), '<a><b><strong><u><em>');
  162. echo "</td></tr>\n";
  163. }
  164. echo "</table>\n\n";
  165. }
  166. $textTag =& $package->tags('@text');
  167. if ($textTag) {
  168. echo '<h1>Namespace ', $package->name(), " Description</h1>\n\n";
  169. echo '<div class="comment" id="overview_description">'. $this->_processInlineTags($textTag), "</div>\n\n";
  170. }
  171. echo "<hr>\n\n";
  172. $this->_output = ob_get_contents();
  173. ob_end_clean();
  174. $this->_write($package->asPath().'/package-summary.html', $package->name(), TRUE);
  175. if ($displayTree) {
  176. $this->_sections[0] = array('title' => 'Overview', 'url' => 'overview-summary.html');
  177. $this->_sections[1] = array('title' => 'Namespace', 'url' => $package->asPath().'/package-summary.html', 'relative' => TRUE);
  178. $this->_sections[2] = array('title' => 'Class');
  179. //$this->_sections[3] = array('title' => 'Use');
  180. $this->_sections[4] = array('title' => 'Tree', 'url' => $package->asPath().'/package-tree.html', 'selected' => TRUE, 'relative' => TRUE);
  181. if ($doclet->includeSource()) $this->_sections[5] = array('title' => 'Files', 'url' => 'overview-files.html');
  182. $this->_sections[6] = array('title' => 'Deprecated', 'url' => 'deprecated-list.html');
  183. $this->_sections[7] = array('title' => 'Todo', 'url' => 'todo-list.html');
  184. $this->_sections[8] = array('title' => 'Index', 'url' => 'index-all.html');
  185. $this->_id = 'tree';
  186. $tree = array();
  187. $classes =& $package->ordinaryClasses();
  188. if ($classes) {
  189. ksort($classes);
  190. foreach ($classes as $class) {
  191. $this->_buildTree($tree, $class);
  192. }
  193. }
  194. ob_start();
  195. echo "<hr>\n\n";
  196. echo '<h1>Class Hierarchy for Package ', $package->name(),'</h1>';
  197. $this->_displayTree($tree);
  198. $this->_output = ob_get_contents();
  199. ob_end_clean();
  200. $this->_write($package->asPath().'/package-tree.html', $package->name(), TRUE);
  201. }
  202. }
  203. }
  204. /**
  205. * Build the class tree branch for the given element
  206. *
  207. * @param ClassDoc[] tree
  208. * @param ClassDoc element
  209. */
  210. public function _buildTree(&$tree, &$element)
  211. {
  212. $tree[$element->name()] = $element;
  213. if ($element->superclass()) {
  214. $rootDoc =& $this->_doclet->rootDoc();
  215. $superclass =& $rootDoc->classNamed($element->superclass());
  216. if ($superclass) {
  217. $this->_buildTree($tree, $superclass);
  218. }
  219. }
  220. }
  221. /**
  222. * Build the class tree branch for the given element
  223. *
  224. * @param ClassDoc[] tree
  225. * @param str parent
  226. */
  227. public function _displayTree($tree, $parent = NULL)
  228. {
  229. $outputList = TRUE;
  230. foreach ($tree as $name => $element) {
  231. if ($element->superclass() == $parent) {
  232. if ($outputList) echo "<ul>\n";
  233. echo '<li><a href="', str_repeat('../', $this->_depth), $element->asPath(), '">', $element->qualifiedName(), '</a>';
  234. $this->_displayTree($tree, $name);
  235. echo "</li>\n";
  236. $outputList = FALSE;
  237. }
  238. }
  239. if (!$outputList) echo "</ul>\n";
  240. }
  241. }