PageRenderTime 456ms CodeModel.GetById 104ms app.highlight 187ms RepoModel.GetById 85ms app.codeStats 1ms

/.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
  1<?php
  2/*
  3PHPDoctor: The PHP Documentation Creator
  4Copyright (C) 2004 Paul James <paul@peej.co.uk>
  5
  6This program is free software; you can redistribute it and/or modify
  7it under the terms of the GNU General Public License as published by
  8the Free Software Foundation; either version 2 of the License, or
  9(at your option) any later version.
 10
 11This program is distributed in the hope that it will be useful,
 12but WITHOUT ANY WARRANTY; without even the implied warranty of
 13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14GNU General Public License for more details.
 15
 16You should have received a copy of the GNU General Public License
 17along with this program; if not, write to the Free Software
 18Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 19*/
 20
 21/** This generates the HTML API documentation for each individual interface
 22 * and class.
 23 *
 24 * @package PHPDoctor\Doclets\Standard
 25 */
 26class ClassWriter extends HTMLWriter
 27{
 28
 29	/** Build the class definitons.
 30	 *
 31	 * @param Doclet doclet
 32	 */
 33	function classWriter(&$doclet)
 34    {
 35	
 36		parent::HTMLWriter($doclet);
 37		
 38		$this->_id = 'definition';
 39
 40		$rootDoc =& $this->_doclet->rootDoc();
 41		$phpdoctor =& $this->_doclet->phpdoctor();
 42		
 43		$packages =& $rootDoc->packages();
 44        ksort($packages);
 45
 46		foreach ($packages as $packageName => $package) {
 47
 48			$this->_sections[0] = array('title' => 'Overview', 'url' => 'overview-summary.html');
 49			$this->_sections[1] = array('title' => 'Namespace', 'url' => $package->asPath().'/package-summary.html');
 50			$this->_sections[2] = array('title' => 'Class', 'selected' => TRUE);
 51			//$this->_sections[3] = array('title' => 'Use');
 52			if ($phpdoctor->getOption('tree')) $this->_sections[4] = array('title' => 'Tree', 'url' => $package->asPath().'/package-tree.html');
 53			if ($doclet->includeSource()) $this->_sections[5] = array('title' => 'Files', 'url' => 'overview-files.html');
 54			$this->_sections[6] = array('title' => 'Deprecated', 'url' => 'deprecated-list.html');
 55			$this->_sections[7] = array('title' => 'Todo', 'url' => 'todo-list.html');
 56			$this->_sections[8] = array('title' => 'Index', 'url' => 'index-all.html');
 57			
 58			$this->_depth = $package->depth() + 1;
 59			
 60			$classes =& $package->allClasses();
 61			
 62			if ($classes) {
 63                ksort($classes);
 64				foreach ($classes as $name => $class) {
 65					
 66					ob_start();
 67					
 68					echo "<hr>\n\n";
 69					
 70					echo '<div class="qualifiedName">', $class->qualifiedName(), "</div>\n";
 71					$this->_sourceLocation($class);
 72					
 73					if ($class->isInterface()) {
 74						echo '<h1>Interface ', $class->name(), "</h1>\n\n";
 75					} else {
 76						echo '<h1>Class ', $class->name(), "</h1>\n\n";
 77					}
 78					
 79					echo '<pre class="tree">';
 80					$result = $this->_buildTree($rootDoc, $classes[$name]);
 81					echo $result[0];
 82					echo "</pre>\n\n";
 83					
 84					$implements =& $class->interfaces();
 85					if (count($implements) > 0) {
 86						echo "<dl>\n";
 87						echo "<dt>All Implemented Interfaces:</dt>\n";
 88						echo '<dd>';
 89						foreach ($implements as $interface) {
 90						    echo '<a href="', str_repeat('../', $this->_depth), $interface->asPath(), '">';
 91						    if ($interface->packageName() != $class->packageName()) {
 92						        echo $interface->packageName(), '\\';
 93						    }
 94						    echo $interface->name(), '</a> ';
 95						}
 96						echo "</dd>\n";
 97						echo "</dl>\n\n";
 98					}
 99					
100					echo "<hr>\n\n";
101					
102					if ($class->isInterface()) {
103						echo '<p class="signature">', $class->modifiers(), ' interface <strong>', $class->name(), '</strong>';
104					} else {
105						echo '<p class="signature">', $class->modifiers(), ' class <strong>', $class->name(), '</strong>';
106					}
107					if ($class->superclass()) {
108						$superclass =& $rootDoc->classNamed($class->superclass());
109						if ($superclass) {
110							echo '<br>extends <a href="', str_repeat('../', $this->_depth), $superclass->asPath(), '">', $superclass->name(), "</a>\n\n";
111						} else {
112							echo '<br>extends ', $class->superclass(), "\n\n";
113						}
114					}
115					echo "</p>\n\n";
116					
117					$textTag =& $class->tags('@text');
118					if ($textTag) {
119						echo '<div class="comment" id="overview_description">', $this->_processInlineTags($textTag), "</div>\n\n";
120					}
121
122					$this->_processTags($class->tags());
123
124					echo "<hr>\n\n";
125
126					$constants =& $class->constants();
127                    ksort($constants);
128					$fields =& $class->fields();
129                    ksort($fields);
130					$methods =& $class->methods();
131                    ksort($methods);
132
133					if ($constants) {
134						echo '<table id="summary_field">', "\n";
135						echo '<tr><th colspan="2">Constant Summary</th></tr>', "\n";
136						foreach ($constants as $field) {
137							$textTag =& $field->tags('@text');
138							echo "<tr>\n";
139							echo '<td class="type">', $field->modifiers(FALSE), ' ', $field->typeAsString(), "</td>\n";
140							echo '<td class="description">';
141							echo '<p class="name"><a href="#', $field->name(), '">';
142							if (is_null($field->constantValue())) echo '$';
143							echo $field->name(), '</a></p>';
144							if ($textTag) {
145								echo '<p class="description">', strip_tags($this->_processInlineTags($textTag, TRUE), '<a><b><strong><u><em>'), '</p>';
146							}
147							echo "</td>\n";
148							echo "</tr>\n";
149						}
150						echo "</table>\n\n";
151					}
152					
153					if ($fields) {
154						echo '<table id="summary_field">', "\n";
155						echo '<tr><th colspan="2">Field Summary</th></tr>', "\n";
156						foreach ($fields as $field) {
157							$textTag =& $field->tags('@text');
158							echo "<tr>\n";
159							echo '<td class="type">', $field->modifiers(FALSE), ' ', $field->typeAsString(), "</td>\n";
160							echo '<td class="description">';
161							echo '<p class="name"><a href="#', $field->name(), '">';
162							if (is_null($field->constantValue())) echo '$';
163							echo $field->name(), '</a></p>';
164							if ($textTag) {
165								echo '<p class="description">', strip_tags($this->_processInlineTags($textTag, TRUE), '<a><b><strong><u><em>'), '</p>';
166							}
167							echo "</td>\n";
168							echo "</tr>\n";
169						}
170						echo "</table>\n\n";
171					}
172					
173					if ($class->superclass()) {
174                        $superclass =& $rootDoc->classNamed($class->superclass());
175                        if ($superclass) {
176                            $this->inheritFields($superclass, $rootDoc, $package);
177                        }
178					}
179
180					if ($methods) {
181						echo '<table id="summary_method">', "\n";
182						echo '<tr><th colspan="2">Method Summary</th></tr>', "\n";
183                        foreach($methods as $method) {
184                            $textTag =& $method->tags('@text');
185                            echo "<tr>\n";
186                            echo '<td class="type">', $method->modifiers(FALSE), ' ', $method->returnTypeAsString(), "</td>\n";
187                            echo '<td class="description">';
188                            echo '<p class="name"><a href="#', $method->name(), '()">', $method->name(), '</a>', $method->flatSignature(), '</p>';
189                            if ($textTag) {
190                                echo '<p class="description">', strip_tags($this->_processInlineTags($textTag, TRUE), '<a><b><strong><u><em>'), '</p>';
191                            }
192                            echo "</td>\n";
193                            echo "</tr>\n";
194                        }
195						echo "</table>\n\n";
196					}
197					
198					if ($class->superclass()) {
199                        $superclass =& $rootDoc->classNamed($class->superclass());
200                        if ($superclass) {
201                            $this->inheritMethods($superclass, $rootDoc, $package);
202                        }
203					}
204
205					if ($constants) {
206						echo '<h2 id="detail_field">Constant Detail</h2>', "\n";
207						foreach($constants as $field) {
208							$textTag =& $field->tags('@text');
209							$type =& $field->type();
210							$this->_sourceLocation($field);
211							echo '<h3 id="', $field->name(),'">', $field->name(), "</h3>\n";
212							echo '<code class="signature">', $field->modifiers(), ' ', $field->typeAsString(), ' <strong>';
213							if (is_null($field->constantValue())) echo '$';
214							echo $field->name(), '</strong>';
215							if (!is_null($field->value())) echo ' = ', htmlspecialchars($field->value());
216							echo "</code>\n";
217                            echo '<div class="details">', "\n";
218							if ($textTag) {
219								echo $this->_processInlineTags($textTag);
220							}
221							$this->_processTags($field->tags());
222                            echo "</div>\n\n";
223							echo "<hr>\n\n";
224						}
225					}
226
227					if ($fields) {
228						echo '<h2 id="detail_field">Field Detail</h2>', "\n";
229						foreach($fields as $field) {
230							$textTag =& $field->tags('@text');
231							$type =& $field->type();
232							$this->_sourceLocation($field);
233							echo '<h3 id="', $field->name(),'">', $field->name(), "</h3>\n";
234							echo '<code class="signature">', $field->modifiers(), ' ', $field->typeAsString(), ' <strong>';
235							if (is_null($field->constantValue())) echo '$';
236							echo $field->name(), '</strong>';
237							if (!is_null($field->value())) echo ' = ', htmlspecialchars($field->value());
238							echo "</code>\n";
239                            echo '<div class="details">', "\n";
240							if ($textTag) {
241								echo $this->_processInlineTags($textTag);
242							}
243							$this->_processTags($field->tags());
244                            echo "</div>\n\n";
245							echo "<hr>\n\n";
246						}
247					}
248					
249					if ($methods) {
250						echo '<h2 id="detail_method">Method Detail</h2>', "\n";
251                        foreach($methods as $method) {
252                            $textTag =& $method->tags('@text');
253                            $this->_sourceLocation($method);
254                            echo '<h3 id="', $method->name(),'()">', $method->name(), "</h3>\n";
255                            echo '<code class="signature">', $method->modifiers(), ' ', $method->returnTypeAsString(), ' <strong>';
256                            echo $method->name(), '</strong>', $method->flatSignature();
257                            echo "</code>\n";
258                            echo '<div class="details">', "\n";
259                            if ($textTag) {
260                                echo $this->_processInlineTags($textTag);
261                            }
262                            $this->_processTags($method->tags());
263                            echo "</div>\n\n";
264                            echo "<hr>\n\n";
265                        }
266					}
267
268					$this->_output = ob_get_contents();
269					ob_end_clean();
270					
271					$this->_write($package->asPath().'/'.strtolower($class->name()).'.html', $class->name(), TRUE);
272				}
273			}
274		}
275    }
276
277	/** Build the class hierarchy tree which is placed at the top of the page.
278	 *
279	 * @param RootDoc rootDoc The root doc
280	 * @param ClassDoc class Class to generate tree for
281	 * @param int depth Depth of recursion
282	 * @return mixed[]
283	 */
284	function _buildTree(&$rootDoc, &$class, $depth = NULL)
285    {
286		if ($depth === NULL) {
287			$start = TRUE;
288			$depth = 0;
289		} else {
290			$start = FALSE;
291		}
292		$output = '';
293		$undefinedClass = FALSE;
294		if ($class->superclass()) {
295			$superclass =& $rootDoc->classNamed($class->superclass());
296			if ($superclass) {
297				$result = $this->_buildTree($rootDoc, $superclass, $depth);
298				$output .= $result[0];
299				$depth = ++$result[1];
300			} else {
301				$output .= $class->superclass().'<br>';
302				$output .= str_repeat('   ', $depth).' └─';
303				$depth++;
304				$undefinedClass = TRUE;
305			}
306		}
307		if ($depth > 0 && !$undefinedClass) {
308			$output .= str_repeat('   ', $depth).' └─';
309		}
310		if ($start) {
311			$output .= '<strong>'.$class->name().'</strong><br />';
312		} else {
313			$output .= '<a href="'.str_repeat('../', $this->_depth).$class->asPath().'">'.$class->name().'</a><br>';
314		}
315		return array($output, $depth);
316	}
317	
318	/** Display the inherited fields of an element. This method calls itself
319	 * recursively if the element has a parent class.
320	 *
321	 * @param ProgramElementDoc element
322	 * @param RootDoc rootDoc
323	 * @param PackageDoc package
324	 */
325	function inheritFields(&$element, &$rootDoc, &$package)
326    {
327		$fields =& $element->fields();
328		if ($fields) {
329            ksort($fields);
330			$num = count($fields); $foo = 0;
331			echo '<table class="inherit">', "\n";
332			echo '<tr><th colspan="2">Fields inherited from ', $element->qualifiedName(), "</th></tr>\n";
333			echo '<tr><td>';
334			foreach($fields as $field) {
335				echo '<a href="', str_repeat('../', $this->_depth), $field->asPath(), '">', $field->name(), '</a>';
336				if (++$foo < $num) {
337					echo ', ';
338				}
339			}
340			echo '</td></tr>';
341			echo "</table>\n\n";
342			if ($element->superclass()) {
343                $superclass =& $rootDoc->classNamed($element->superclass());
344                if ($superclass) {
345                    $this->inheritFields($superclass, $rootDoc, $package);
346                }
347			}
348		}
349	}
350	
351	/** Display the inherited methods of an element. This method calls itself
352	 * recursively if the element has a parent class.
353	 *
354	 * @param ProgramElementDoc element
355	 * @param RootDoc rootDoc
356	 * @param PackageDoc package
357	 */
358	function inheritMethods(&$element, &$rootDoc, &$package)
359    {
360		$methods =& $element->methods();
361		if ($methods) {
362            ksort($methods);
363			$num = count($methods); $foo = 0;
364			echo '<table class="inherit">', "\n";
365			echo '<tr><th colspan="2">Methods inherited from ', $element->qualifiedName(), "</th></tr>\n";
366			echo '<tr><td>';
367			foreach($methods as $method) {
368				echo '<a href="', str_repeat('../', $this->_depth), $method->asPath(), '">', $method->name(), '</a>';
369				if (++$foo < $num) {
370					echo ', ';
371				}
372			}
373			echo '</td></tr>';
374			echo "</table>\n\n";
375			if ($element->superclass()) {
376                $superclass =& $rootDoc->classNamed($element->superclass());
377                if ($superclass) {
378                    $this->inheritMethods($superclass, $rootDoc, $package);
379                }
380			}
381		}
382	}
383
384}
385
386?>