PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/.dev/lib/phpdoctor/doclets/standard/classWriter.php

https://github.com/istran/core
PHP | 386 lines | 306 code | 31 blank | 49 comment | 46 complexity | 35d6ede24634013ac2b798af3f91ad55 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause
  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 HTML API documentation for each individual interface
  18. * and class.
  19. *
  20. * @package PHPDoctor\Doclets\Standard
  21. */
  22. class ClassWriter extends HTMLWriter
  23. {
  24. /** Build the class definitons.
  25. *
  26. * @param Doclet doclet
  27. */
  28. function classWriter(&$doclet)
  29. {
  30. parent::HTMLWriter($doclet);
  31. $this->_id = 'definition';
  32. $rootDoc =& $this->_doclet->rootDoc();
  33. $phpdoctor =& $this->_doclet->phpdoctor();
  34. $packages =& $rootDoc->packages();
  35. ksort($packages);
  36. foreach ($packages as $packageName => $package) {
  37. $this->_sections[0] = array('title' => 'Overview', 'url' => 'overview-summary.html');
  38. $this->_sections[1] = array('title' => 'Namespace', 'url' => $package->asPath().'/package-summary.html');
  39. $this->_sections[2] = array('title' => 'Class', 'selected' => TRUE);
  40. //$this->_sections[3] = array('title' => 'Use');
  41. if ($phpdoctor->getOption('tree')) $this->_sections[4] = array('title' => 'Tree', 'url' => $package->asPath().'/package-tree.html');
  42. if ($doclet->includeSource()) $this->_sections[5] = array('title' => 'Files', 'url' => 'overview-files.html');
  43. $this->_sections[6] = array('title' => 'Deprecated', 'url' => 'deprecated-list.html');
  44. $this->_sections[7] = array('title' => 'Todo', 'url' => 'todo-list.html');
  45. $this->_sections[8] = array('title' => 'Index', 'url' => 'index-all.html');
  46. $this->_depth = $package->depth() + 1;
  47. $classes =& $package->allClasses();
  48. if ($classes) {
  49. ksort($classes);
  50. foreach ($classes as $name => $class) {
  51. ob_start();
  52. echo "<hr>\n\n";
  53. echo '<div class="qualifiedName">', $class->qualifiedName(), "</div>\n";
  54. $this->_sourceLocation($class);
  55. if ($class->isInterface()) {
  56. echo '<h1>Interface ', $class->name(), "</h1>\n\n";
  57. } else {
  58. echo '<h1>Class ', $class->name(), "</h1>\n\n";
  59. }
  60. echo '<pre class="tree">';
  61. $result = $this->_buildTree($rootDoc, $classes[$name]);
  62. echo $result[0];
  63. echo "</pre>\n\n";
  64. $implements =& $class->interfaces();
  65. if (count($implements) > 0) {
  66. echo "<dl>\n";
  67. echo "<dt>All Implemented Interfaces:</dt>\n";
  68. echo '<dd>';
  69. foreach ($implements as $interface) {
  70. echo '<a href="', str_repeat('../', $this->_depth), $interface->asPath(), '">';
  71. if ($interface->packageName() != $class->packageName()) {
  72. echo $interface->packageName(), '\\';
  73. }
  74. echo $interface->name(), '</a> ';
  75. }
  76. echo "</dd>\n";
  77. echo "</dl>\n\n";
  78. }
  79. echo "<hr>\n\n";
  80. if ($class->isInterface()) {
  81. echo '<p class="signature">', $class->modifiers(), ' interface <strong>', $class->name(), '</strong>';
  82. } else {
  83. echo '<p class="signature">', $class->modifiers(), ' class <strong>', $class->name(), '</strong>';
  84. }
  85. if ($class->superclass()) {
  86. $superclass =& $rootDoc->classNamed($class->superclass());
  87. if ($superclass) {
  88. echo '<br>extends <a href="', str_repeat('../', $this->_depth), $superclass->asPath(), '">', $superclass->name(), "</a>\n\n";
  89. } else {
  90. echo '<br>extends ', $class->superclass(), "\n\n";
  91. }
  92. }
  93. echo "</p>\n\n";
  94. $textTag =& $class->tags('@text');
  95. if ($textTag) {
  96. echo '<div class="comment" id="overview_description">', $this->_processInlineTags($textTag), "</div>\n\n";
  97. }
  98. $this->_processTags($class->tags());
  99. echo "<hr>\n\n";
  100. $constants =& $class->constants();
  101. ksort($constants);
  102. $fields =& $class->fields();
  103. ksort($fields);
  104. $methods =& $class->methods();
  105. ksort($methods);
  106. if ($constants) {
  107. echo '<table id="summary_field">', "\n";
  108. echo '<tr><th colspan="2">Constant Summary</th></tr>', "\n";
  109. foreach ($constants as $field) {
  110. $textTag =& $field->tags('@text');
  111. echo "<tr>\n";
  112. echo '<td class="type">', $field->modifiers(FALSE), ' ', $field->typeAsString(), "</td>\n";
  113. echo '<td class="description">';
  114. echo '<p class="name"><a href="#', $field->name(), '">';
  115. if (is_null($field->constantValue())) echo '$';
  116. echo $field->name(), '</a></p>';
  117. if ($textTag) {
  118. echo '<p class="description">', strip_tags($this->_processInlineTags($textTag, TRUE), '<a><b><strong><u><em>'), '</p>';
  119. }
  120. echo "</td>\n";
  121. echo "</tr>\n";
  122. }
  123. echo "</table>\n\n";
  124. }
  125. if ($fields) {
  126. echo '<table id="summary_field">', "\n";
  127. echo '<tr><th colspan="2">Field Summary</th></tr>', "\n";
  128. foreach ($fields as $field) {
  129. $textTag =& $field->tags('@text');
  130. echo "<tr>\n";
  131. echo '<td class="type">', $field->modifiers(FALSE), ' ', $field->typeAsString(), "</td>\n";
  132. echo '<td class="description">';
  133. echo '<p class="name"><a href="#', $field->name(), '">';
  134. if (is_null($field->constantValue())) echo '$';
  135. echo $field->name(), '</a></p>';
  136. if ($textTag) {
  137. echo '<p class="description">', strip_tags($this->_processInlineTags($textTag, TRUE), '<a><b><strong><u><em>'), '</p>';
  138. }
  139. echo "</td>\n";
  140. echo "</tr>\n";
  141. }
  142. echo "</table>\n\n";
  143. }
  144. if ($class->superclass()) {
  145. $superclass =& $rootDoc->classNamed($class->superclass());
  146. if ($superclass) {
  147. $this->inheritFields($superclass, $rootDoc, $package);
  148. }
  149. }
  150. if ($methods) {
  151. echo '<table id="summary_method">', "\n";
  152. echo '<tr><th colspan="2">Method Summary</th></tr>', "\n";
  153. foreach($methods as $method) {
  154. $textTag =& $method->tags('@text');
  155. echo "<tr>\n";
  156. echo '<td class="type">', $method->modifiers(FALSE), ' ', $method->returnTypeAsString(), "</td>\n";
  157. echo '<td class="description">';
  158. echo '<p class="name"><a href="#', $method->name(), '()">', $method->name(), '</a>', $method->flatSignature(), '</p>';
  159. if ($textTag) {
  160. echo '<p class="description">', strip_tags($this->_processInlineTags($textTag, TRUE), '<a><b><strong><u><em>'), '</p>';
  161. }
  162. echo "</td>\n";
  163. echo "</tr>\n";
  164. }
  165. echo "</table>\n\n";
  166. }
  167. if ($class->superclass()) {
  168. $superclass =& $rootDoc->classNamed($class->superclass());
  169. if ($superclass) {
  170. $this->inheritMethods($superclass, $rootDoc, $package);
  171. }
  172. }
  173. if ($constants) {
  174. echo '<h2 id="detail_field">Constant Detail</h2>', "\n";
  175. foreach($constants as $field) {
  176. $textTag =& $field->tags('@text');
  177. $type =& $field->type();
  178. $this->_sourceLocation($field);
  179. echo '<h3 id="', $field->name(),'">', $field->name(), "</h3>\n";
  180. echo '<code class="signature">', $field->modifiers(), ' ', $field->typeAsString(), ' <strong>';
  181. if (is_null($field->constantValue())) echo '$';
  182. echo $field->name(), '</strong>';
  183. if (!is_null($field->value())) echo ' = ', htmlspecialchars($field->value());
  184. echo "</code>\n";
  185. echo '<div class="details">', "\n";
  186. if ($textTag) {
  187. echo $this->_processInlineTags($textTag);
  188. }
  189. $this->_processTags($field->tags());
  190. echo "</div>\n\n";
  191. echo "<hr>\n\n";
  192. }
  193. }
  194. if ($fields) {
  195. echo '<h2 id="detail_field">Field Detail</h2>', "\n";
  196. foreach($fields as $field) {
  197. $textTag =& $field->tags('@text');
  198. $type =& $field->type();
  199. $this->_sourceLocation($field);
  200. echo '<h3 id="', $field->name(),'">', $field->name(), "</h3>\n";
  201. echo '<code class="signature">', $field->modifiers(), ' ', $field->typeAsString(), ' <strong>';
  202. if (is_null($field->constantValue())) echo '$';
  203. echo $field->name(), '</strong>';
  204. if (!is_null($field->value())) echo ' = ', htmlspecialchars($field->value());
  205. echo "</code>\n";
  206. echo '<div class="details">', "\n";
  207. if ($textTag) {
  208. echo $this->_processInlineTags($textTag);
  209. }
  210. $this->_processTags($field->tags());
  211. echo "</div>\n\n";
  212. echo "<hr>\n\n";
  213. }
  214. }
  215. if ($methods) {
  216. echo '<h2 id="detail_method">Method Detail</h2>', "\n";
  217. foreach($methods as $method) {
  218. $textTag =& $method->tags('@text');
  219. $this->_sourceLocation($method);
  220. echo '<h3 id="', $method->name(),'()">', $method->name(), "</h3>\n";
  221. echo '<code class="signature">', $method->modifiers(), ' ', $method->returnTypeAsString(), ' <strong>';
  222. echo $method->name(), '</strong>', $method->flatSignature();
  223. echo "</code>\n";
  224. echo '<div class="details">', "\n";
  225. if ($textTag) {
  226. echo $this->_processInlineTags($textTag);
  227. }
  228. $this->_processTags($method->tags());
  229. echo "</div>\n\n";
  230. echo "<hr>\n\n";
  231. }
  232. }
  233. $this->_output = ob_get_contents();
  234. ob_end_clean();
  235. $this->_write($package->asPath().'/'.strtolower($class->name()).'.html', $class->name(), TRUE);
  236. }
  237. }
  238. }
  239. }
  240. /** Build the class hierarchy tree which is placed at the top of the page.
  241. *
  242. * @param RootDoc rootDoc The root doc
  243. * @param ClassDoc class Class to generate tree for
  244. * @param int depth Depth of recursion
  245. * @return mixed[]
  246. */
  247. function _buildTree(&$rootDoc, &$class, $depth = NULL)
  248. {
  249. if ($depth === NULL) {
  250. $start = TRUE;
  251. $depth = 0;
  252. } else {
  253. $start = FALSE;
  254. }
  255. $output = '';
  256. $undefinedClass = FALSE;
  257. if ($class->superclass()) {
  258. $superclass =& $rootDoc->classNamed($class->superclass());
  259. if ($superclass) {
  260. $result = $this->_buildTree($rootDoc, $superclass, $depth);
  261. $output .= $result[0];
  262. $depth = ++$result[1];
  263. } else {
  264. $output .= $class->superclass().'<br>';
  265. $output .= str_repeat(' ', $depth).' └─';
  266. $depth++;
  267. $undefinedClass = TRUE;
  268. }
  269. }
  270. if ($depth > 0 && !$undefinedClass) {
  271. $output .= str_repeat(' ', $depth).' └─';
  272. }
  273. if ($start) {
  274. $output .= '<strong>'.$class->name().'</strong><br />';
  275. } else {
  276. $output .= '<a href="'.str_repeat('../', $this->_depth).$class->asPath().'">'.$class->name().'</a><br>';
  277. }
  278. return array($output, $depth);
  279. }
  280. /** Display the inherited fields of an element. This method calls itself
  281. * recursively if the element has a parent class.
  282. *
  283. * @param ProgramElementDoc element
  284. * @param RootDoc rootDoc
  285. * @param PackageDoc package
  286. */
  287. function inheritFields(&$element, &$rootDoc, &$package)
  288. {
  289. $fields =& $element->fields();
  290. if ($fields) {
  291. ksort($fields);
  292. $num = count($fields); $foo = 0;
  293. echo '<table class="inherit">', "\n";
  294. echo '<tr><th colspan="2">Fields inherited from ', $element->qualifiedName(), "</th></tr>\n";
  295. echo '<tr><td>';
  296. foreach($fields as $field) {
  297. echo '<a href="', str_repeat('../', $this->_depth), $field->asPath(), '">', $field->name(), '</a>';
  298. if (++$foo < $num) {
  299. echo ', ';
  300. }
  301. }
  302. echo '</td></tr>';
  303. echo "</table>\n\n";
  304. if ($element->superclass()) {
  305. $superclass =& $rootDoc->classNamed($element->superclass());
  306. if ($superclass) {
  307. $this->inheritFields($superclass, $rootDoc, $package);
  308. }
  309. }
  310. }
  311. }
  312. /** Display the inherited methods of an element. This method calls itself
  313. * recursively if the element has a parent class.
  314. *
  315. * @param ProgramElementDoc element
  316. * @param RootDoc rootDoc
  317. * @param PackageDoc package
  318. */
  319. function inheritMethods(&$element, &$rootDoc, &$package)
  320. {
  321. $methods =& $element->methods();
  322. if ($methods) {
  323. ksort($methods);
  324. $num = count($methods); $foo = 0;
  325. echo '<table class="inherit">', "\n";
  326. echo '<tr><th colspan="2">Methods inherited from ', $element->qualifiedName(), "</th></tr>\n";
  327. echo '<tr><td>';
  328. foreach($methods as $method) {
  329. echo '<a href="', str_repeat('../', $this->_depth), $method->asPath(), '">', $method->name(), '</a>';
  330. if (++$foo < $num) {
  331. echo ', ';
  332. }
  333. }
  334. echo '</td></tr>';
  335. echo "</table>\n\n";
  336. if ($element->superclass()) {
  337. $superclass =& $rootDoc->classNamed($element->superclass());
  338. if ($superclass) {
  339. $this->inheritMethods($superclass, $rootDoc, $package);
  340. }
  341. }
  342. }
  343. }
  344. }
  345. ?>