3 * Coordinates several Phpdoc Object to parse and render source files.
\r
6 * @version $Id: Phpdoc.php,v 1.4 2000/12/03 20:30:42 uw Exp $
\r
8 class Phpdoc extends PhpdocSetupHandler {
\r
11 * Result from the indexer
\r
16 var $indexer_result = array();
\r
19 * Print status messages
\r
21 var $flag_output = true;
\r
24 * Calls the command line handler if necessary.
\r
26 * @global array $argc, string $PHP_SELF
\r
29 global $argc, $PHP_SELF;
\r
31 $this->target = $PHP_SELF."apidoc/";
\r
34 $this->handleArgv();
\r
36 } // end constructor
\r
39 * Starts the parser.
\r
42 * @throws PhpdocError
\r
47 $this->warn = new PhpdocWarning;
\r
49 $errors = $this->checkStatus();
\r
50 if (0 != count($errors)) {
\r
53 while (list($k, $error)=each($errors))
\r
54 $this->err[] = new PhpdocError($error["msg"]."Errno = ".$error["errno"], 9, __FILE__, __LINE__);
\r
59 $this->outl("Parser starts...");
\r
61 // create some objects
\r
62 $fileHandler = new PhpdocFileHandler;
\r
63 $parser = new PhpdocParser(true);
\r
64 $classAnalyser = new PhpdocClassAnalyser;
\r
65 $moduleAnalyser = new PhpdocModuleAnalyser;
\r
67 $indexer = new PhpdocIndexer;
\r
69 $classExporter = new PhpdocXMLClassExporter();
\r
70 $classExporter->setPath($this->target);
\r
72 $moduleExporter = new PhpdocXMLModuleExporter();
\r
73 $moduleExporter->setPath($this->target);
\r
75 $indexExporter = new PhpdocXMLIndexExporter();
\r
76 $indexExporter->setPath($this->target);
\r
78 $warningExporter = new PhpdocXMLWarningExporter();
\r
79 $warningExporter->setPath($this->target);
\r
81 // This will change one fine day!
\r
82 $parser->warn = $this->warn;
\r
83 $classAnalyser->warn = $this->warn;
\r
84 $moduleAnalyser->warn = $this->warn;
\r
85 $classExporter->warn = $this->warn;
\r
86 $moduleExporter->warn = $this->warn;
\r
87 $indexer->warn = $this->warn;
\r
89 $sourcefiles = $fileHandler->getFilesInDirectory($this->sourceDirectory, $this->sourceFileSuffix);
\r
90 $parser->setPhpSourcecodeFiles($fileHandler->get($sourcefiles));
\r
92 $this->outl("... preparse to find modulegroups and classtrees.");
\r
93 $parser->preparse();
\r
95 $this->outl("... parsing classes.");
\r
96 while ($classtree = $parser->getClassTree()) {
\r
98 $classAnalyser->setClasses( $classtree, $parser->current_baseclass );
\r
99 $classAnalyser->analyse();
\r
101 while ($class = $classAnalyser->getClass()) {
\r
102 $indexer->addClass($class);
\r
103 $classExporter->export($class);
\r
106 if (floor(phpversion()) > 3) {
\r
108 $indexExporter->exportClasstree($indexer->getClasstree(), $parser->current_baseclass);
\r
112 $classtree = $indexer->getClasstree();
\r
113 $base = $parser->current_baseclass;
\r
114 $indexExporter->exportClasstree($classtree, $base);
\r
120 $this->outl("... parsing modules.");
\r
121 while ($modulegroup = $parser->getModulegroup()) {
\r
123 $moduleAnalyser->setModulegroup( $modulegroup );
\r
124 $moduleAnalyser->analyse();
\r
126 while ($module = $moduleAnalyser->getModule()) {
\r
127 $indexer->addModule($module);
\r
128 $moduleExporter->export($module);
\r
131 if (floor(phpversion()) > 3) {
\r
133 $indexExporter->exportModulegroup($indexer->getModulegroup());
\r
137 $modulegroup = $indexer->getModulegroup();
\r
138 $indexExporter->exportModulegroup($modulegroup);
\r
144 $this->outl("... writing packagelist.");
\r
145 if (floor(phpversion()) > 3) {
\r
147 $indexExporter->exportPackagelist($indexer->getPackages());
\r
148 $indexExporter->exportElementlist($indexer->getElementlist());
\r
152 $packages = $indexer->getPackages();
\r
153 $indexExporter->exportPackagelist($packages);
\r
154 $elements = $indexer->getElementlist();
\r
155 $indexExporter->exportElementlist($elements);
\r
159 $warningExporter->export($parser->warn->getWarnings(), "parser");
\r
160 $warningExporter->export($moduleAnalyser->warn->getWarnings(), "moduleanalyser");
\r
161 $warningExporter->export($classAnalyser->warn->getWarnings(), "classanalyser");
\r
163 $this->outl("Parser finished.");
\r
165 } // end func parse
\r
168 * Renders the PHPDoc XML files as HTML files
\r
170 * @param string Targetformat, currently only "html" is available.
\r
171 * @param string Target directory for the html files
\r
172 * @param string Directory with the html templates
\r
174 * @throws PhpdocError
\r
177 function render($type = "html", $target = "", $template = "") {
\r
179 $this->outl("Starting to render...");
\r
180 $target = ("" == $target) ? $this->target : $this->getCheckedDirname($target);
\r
181 $template = ("" == $template) ? $this->templateRoot : $this->getCheckedDirname($template);
\r
183 switch(strtolower($type)) {
\r
187 $renderer = new PhpdocHTMLRendererManager($target, $template, $this->application, $this->targetFileSuffix);
\r
191 $fileHandler = new PhpdocFileHandler;
\r
192 $files = $fileHandler->getFilesInDirectory($target, "xml");
\r
193 $len = strlen($target);
\r
195 $tpl = new IntegratedTemplate($this->templateRoot);
\r
196 $tpl->loadTemplateFile("xmlfiles.html");
\r
197 $tpl->setCurrentBlock("file_loop");
\r
199 // Do not change the file prefixes!
\r
201 while (list($k, $file) = each($files)) {
\r
203 $tpl->setVariable("FILE", substr($file, $len));
\r
204 $tpl->parseCurrentBlock();
\r
206 if ("class_" == substr($file, $len, 6)) {
\r
208 $renderer->render(substr($file, $len), "class");
\r
210 } else if ("module_" == substr($file, $len, 7)) {
\r
212 $renderer->render(substr($file, $len), "module");
\r
214 } else if ("classtree_" == substr($file, $len, 10)) {
\r
216 $renderer->render(substr($file, $len), "classtree");
\r
218 } else if ("modulegroup_" == substr($file, $len, 12)) {
\r
220 $renderer->render(substr($file, $len), "modulegroup");
\r
222 } else if ("warnings_" == substr($file, $len, 9)) {
\r
224 $renderer->render(substr($file, $len), "warning");
\r
230 $renderer->finish();
\r
231 $fileHandler->createFile($target."phpdoc_xmlfiles".$this->targetFileSuffix, $tpl->get());
\r
233 $this->outl($this->finishInstructions);
\r
235 } // end func render
\r
237 } // end class Phpdoc
\r