/doclets/github_wiki/packageWriter.php
PHP | 254 lines | 172 code | 43 blank | 39 comment | 24 complexity | 0d66017dcf8206cbbd9fd7bcf9b997fc MD5 | raw file
Possible License(s): GPL-2.0
- <?php
- /*
- PHPDoctor: The PHP Documentation Creator
- Copyright (C) 2004 Paul James <paul@peej.co.uk>
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
- /** This generates the README.md files that list the interfaces and
- * classes for a given package.
- *
- * @package PHPDoctor\Doclets\GithubWiki
- */
- class PackageWriter extends MDWriter {
- /** Build the package summaries.
- *
- * @param Doclet doclet
- */
- function packageWriter(&$doclet) {
- parent::MDWriter($doclet);
- $rootDoc = & $this->_doclet->rootDoc();
- $phpdoctor = & $this->_doclet->phpdoctor();
- $displayTree = $phpdoctor->getOption("tree");
- if ($displayTree) {
- $this->_id = "tree";
- $tree = array();
- $classes = & $rootDoc->classes();
- if ($classes) {
- foreach ($classes as $class) {
- $this->_buildTree($tree, $class);
- }
- }
- ob_start();
- echo "\n\n- - -\n\n";
- echo "#Class Hierarchy#\n\n";
- $this->_displayTree($tree);
- $this->_output = ob_get_contents();
- ob_end_clean();
- $this->_write("overview-tree.md");
- }
- $this->_id = "package";
- $packages = & $rootDoc->packages();
- ksort($packages);
- foreach ($packages as $packageName => $package) {
- $this->_depth = $package->depth() + 1;
- ob_start();
- echo "\n\n- - -\n\n";
- echo "#Namespace ", $package->name(), "#\n\n";
- if ($displayTree) {
- echo "<div><a href='{$this->_asURL($package)}/package-tree.md'>View Class Hierarchy for this Package</a></div>\n\n";
- }
- $textTag = & $package->tags("@text");
- if ($textTag) {
- echo "<div class=\"comment\">", $this->_processInlineTags($textTag, TRUE), "</div>\n\n";
- echo "<dl><dt>See:</dt><dd><b><a href=\"#overview_description\">Description</a></b></dd></dl>", "\n\n";
- }
- $classes = & $package->ordinaryClasses();
- if ($classes) {
- ksort($classes);
- echo "<table class=\"title\">", "\n";
- echo "<tr><th colspan=\"2\" class=\"title\">Class Summary</th></tr>", "\n";
- foreach ($classes as $name => $class) {
- $textTag = & $classes[$name]->tags("@text");
- echo "<tr><td class=\"name\"><a href=\"", $this->_asURL($classes[$name]), "\">", $classes[$name]->name(), "</a></td>";
- echo "<td class=\"description\">";
- if ($textTag)
- echo strip_tags($this->_processInlineTags($textTag, TRUE), "<a><b>**<u><em>");
- echo "</td></tr>\n";
- }
- echo "</table>\n\n";
- }
- $interfaces = & $package->interfaces();
- if ($interfaces) {
- ksort($interfaces);
- echo "<table class=\"title\">" . "\n";
- echo "<tr><th colspan=\"2\" class=\"title\">Interface Summary</th></tr>" . "\n";
- foreach ($interfaces as $name => $interface) {
- $textTag = & $interfaces[$name]->tags("@text");
- echo "<tr><td class=\"name\"><a href=\"", $this->_asURL($interfaces[$name]), "\">", $interfaces[$name]->name(), "</a></td>";
- echo "<td class=\"description\">";
- if ($textTag)
- echo strip_tags($this->_processInlineTags($textTag, TRUE), "<a><b>**<u><em>");
- echo "</td></tr>\n";
- }
- echo "</table>\n\n";
- }
- $exceptions = & $package->exceptions();
- if ($exceptions) {
- ksort($exceptions);
- echo "<table class=\"title\">" . "\n";
- echo "<tr><th colspan=\"2\" class=\"title\">Exception Summary</th></tr>" . "\n";
- foreach ($exceptions as $name => $exception) {
- $textTag = & $exceptions[$name]->tags("@text");
- echo "<tr><td class=\"name\"><a href=\"", $this->_asURL($exceptions[$name]), "\">", $exceptions[$name]->name(), "</a></td>";
- echo "<td class=\"description\">";
- if ($textTag)
- echo strip_tags($this->_processInlineTags($textTag, TRUE), "<a><b>**<u><em>");
- echo "</td></tr>\n";
- }
- echo "</table>\n\n";
- }
- $functions = & $package->functions();
- if ($functions) {
- ksort($functions);
- echo "<table class=\"title\">", "\n";
- echo "<tr><th colspan=\"2\" class=\"title\">Function Summary</th></tr>", "\n";
- foreach ($functions as $name => $function) {
- $textTag = & $functions[$name]->tags("@text");
- echo "<tr><td class=\"name\"><a href=\"package-functions.md#", $functions[$name]->name(), "\">", $functions[$name]->name(), "</a></td>";
- echo "<td class=\"description\">";
- if ($textTag)
- echo strip_tags($this->_processInlineTags($textTag, TRUE), "<a><b>**<u><em>");
- echo "</td></tr>\n";
- }
- echo "</table>\n\n";
- }
- $globals = & $package->globals();
- if ($globals) {
- ksort($globals);
- echo "<table class=\"title\">", "\n";
- echo "<tr><th colspan=\"2\" class=\"title\">Global Summary</th></tr>", "\n";
- foreach ($globals as $name => $global) {
- $textTag = & $globals[$name]->tags("@text");
- echo "<tr><td class=\"name\"><a href=\"package-globals.md#", $globals[$name]->name(), "\">", $globals[$name]->name(), "</a></td>";
- echo "<td class=\"description\">";
- if ($textTag)
- echo strip_tags($this->_processInlineTags($textTag, TRUE), "<a><b>**<u><em>");
- echo "</td></tr>\n";
- }
- echo "</table>\n\n";
- }
- $textTag = & $package->tags("@text");
- if ($textTag) {
- echo "#Namespace ", $package->name(), " Description#\n\n";
- echo "<div class=\"comment\" id=\"overview_description\">" . $this->_processInlineTags($textTag), "</div>\n\n";
- }
- echo "- - -\n\n";
- $this->_output = ob_get_contents();
- ob_end_clean();
- $this->_write($this->_normalize($package->_name) . "_README.md");
- if ($displayTree) {
- $this->_id = "tree";
- $tree = array();
- $classes = & $package->ordinaryClasses();
- if ($classes) {
- ksort($classes);
- foreach ($classes as $class) {
- $this->_buildTree($tree, $class);
- }
- }
- ob_start();
- echo "- - -\n\n";
- echo "#Class Hierarchy for Package {$package->name()}";
- echo "\n\n<div><a href='{$this->_asURL($package)}'>Back to package summary</a></div>\n\n";
- $this->_displayTree($tree);
- $this->_output = ob_get_contents();
- ob_end_clean();
- $this->_write($this->_normalize($package->_name) . "_package-tree.md", $package->name(), TRUE);
- }
- }
- }
- /**
- * Build the class tree branch for the given element
- *
- * @param ClassDoc[] tree
- * @param ClassDoc element
- */
- function _buildTree(&$tree, &$element) {
- $tree[$element->name()] = $element;
- if ($element->superclass()) {
- $rootDoc = & $this->_doclet->rootDoc();
- $superclass = & $rootDoc->classNamed($element->superclass());
- if ($superclass) {
- $this->_buildTree($tree, $superclass);
- }
- }
- }
- /**
- * Build the class tree branch for the given element
- *
- * @param ClassDoc[] tree
- * @param str parent
- */
- function _displayTree($tree, $parent = NULL) {
- $outputList = TRUE;
- foreach ($tree as $name => $element) {
- if ($element->superclass() == $parent) {
- if ($outputList)
- echo "<ul>\n";
- echo "<li><a href=\"", $this->_asURL($element), "\">", $element->qualifiedName(), "</a>";
- $this->_displayTree($tree, $name);
- echo "</li>\n";
- $outputList = FALSE;
- }
- }
- if (!$outputList)
- echo "</ul>\n";
- }
- }
- ?>