File: Phpdoc.php

package info (click to toggle)
php4 4.0.3pl1-0potato3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 15,168 kB
  • ctags: 20,556
  • sloc: ansic: 155,237; php: 10,827; sh: 9,608; yacc: 1,874; lex: 1,742; makefile: 788; java: 424; awk: 359; cpp: 335; perl: 181; xml: 57
file content (228 lines) | stat: -rw-r--r-- 6,031 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php
/**
* Coordinates several Phpdoc Object to parse and render source files.
* 
* @access	public
*/
class Phpdoc extends PhpdocSetupHandler {

	/**
	* Result from the indexer
	* @var	array	$indexer
	* @see	render()
	*/
	var $indexer_result = array();
	
	/**
	* Print status messages
	*/
	var $flag_output = true;

	/**
	* Calls the command line handler if necessary.
	*
	* @global $argc, $PHP_SELF
	*/
	function Phpdoc() {
		global $argc, $PHP_SELF;
		
		$this->target = $PHP_SELF."apidoc/";
		
		if ($argc>1) 
			$this->handleArgv();
	} // end constructor

	
	/**
	* Starts the parser. 
	*
	* @return	bool		$ok
	* @throws	PhpdocError
	* @access	public
	* @see		
	*/
	function parse() {
		
		$this->warn = new PhpdocWarning;
		
		$errors = $this->checkStatus();
		if (0!=count($errors)) {
		
			reset($errors);
			while (list($k, $error)=each($errors))
				$this->err[] = new PhpdocError($error["msg"]."Errno = ".$error["errno"], 9, __FILE__, __LINE__);
				
			return false;
		}

		$this->outl("Parser starts...");

		// create some objects
		$fileHandler 		= new PhpdocFileHandler;
		$parser 				= new PhpdocParser(true);
		
		$classAnalyser	= new PhpdocClassAnalyser;
		$moduleAnalyser = new PhpdocModuleAnalyser;
		
		$indexer	= new PhpdocIndexer;				
		
		$classExporter	= new PhpdocXMLClassExporter();
		$classExporter->setPath($this->target);
		
		$moduleExporter = new PhpdocXMLModuleExporter();
		$moduleExporter->setPath($this->target);
		
		$indexExporter = new PhpdocXMLIndexExporter();
		$indexExporter->setPath($this->target);
		
		$warningExporter = new PhpdocXMLWarningExporter();
		$warningExporter->setPath($this->target);
				
		// This will change one fine day! 
		$parser->warn 				= $this->warn;
		$classAnalyser->warn 	= $this->warn;
		$moduleAnalyser->warn = $this->warn;
		$classExporter->warn 	= $this->warn;
		$moduleExporter->warn = $this->warn;
		$indexer->warn 				= $this->warn; 

		$sourcefiles = $fileHandler->getFilesInDirectory($this->sourceDirectory, $this->sourceFileSuffix);
		$parser->setPhpSourcecodeFiles($fileHandler->get($sourcefiles));
		
		$this->outl("... preparse to find modulegroups and classtrees.");
		$parser->preparse();

		$this->outl("... parsing classes.");
		while ($classtree = $parser->getClassTree()) {

			$classAnalyser->setClasses( $classtree, $parser->current_baseclass );
			$classAnalyser->analyse();
			
			while ($class = $classAnalyser->getClass()) {
				$indexer->addClass($class);
				$classExporter->export($class);
			}
			
			if (floor(phpversion())>3) {
				$indexExporter->exportClasstree($indexer->getClasstree(), $parser->current_baseclass);
			} else {
				$classtree = $indexer->getClasstree();
				$base = $parser->current_baseclass;
				$indexExporter->exportClasstree($classtree, $base);
			}
			
		}
			
		$this->outl("... parsing modules.");
		while ($modulegroup = $parser->getModulegroup()) {	

			$moduleAnalyser->setModulegroup( $modulegroup );
			$moduleAnalyser->analyse();
				
			while ($module = $moduleAnalyser->getModule()) {
				$indexer->addModule($module);
				$moduleExporter->export($module);
			}

			if (floor(phpversion())>3) {
				$indexExporter->exportModulegroup($indexer->getModulegroup());
			} else {
				$modulegroup = $indexer->getModulegroup();
				$indexExporter->exportModulegroup($modulegroup);
			}
			
		}

		$this->outl("... writing packagelist.");
		
		if (floor(phpversion())>3) {
			$indexExporter->exportPackagelist($indexer->getPackages());
			$indexExporter->exportElementlist($indexer->getElementlist());
		} else {
			$packages = $indexer->getPackages();
			$indexExporter->exportPackagelist($packages);
			$elements = $indexer->getElementlist();
			$indexExporter->exportElementlist($elements);
		}

		$warningExporter->export($parser->warn->getWarnings(), "parser");
		$warningExporter->export($moduleAnalyser->warn->getWarnings(), "moduleanalyser");
		$warningExporter->export($classAnalyser->warn->getWarnings(), "classanalyser");
		$this->outl("Parser finished.");

		return true;
	} // end func parse
	
	/**
	* Renders the PHPDoc XML files as HTML files 
	*
	* @param	string	Targetformat, currently only "html" is available.
	* @param	string 	Target directory for the html files
	* @param	string	Directory with the html templates
	* @return	bool		$ok
	* @throws	PhpdocError
	* @access	public
	*/
	function render($type="html", $target="", $template="") {

		$this->outl("Starting to render...");
	
		$target = (""==$target) ? $this->target : $this->getCheckedDirname($target);
		$template =	(""==$template) ? $this->templateRoot : $this->getCheckedDirname($template);				
			
		switch(strtolower($type)) {
		
			case "html":
			default:
				$renderer = new PhpdocHTMLRendererManager($target, $template, $this->application);
				break;
		}
		
		$fileHandler 		= new PhpdocFileHandler;
		$files = $fileHandler->getFilesInDirectory($target, "xml");
		$len = strlen($target);
		
		$tpl = new IntegratedTemplate($this->templateRoot);
		$tpl->loadTemplateFile("xmlfiles.html");
		$tpl->setCurrentBlock("file_loop");
		
		// Do not change the file prefixes!
		reset($files);
		while (list($k, $file)=each($files)) {

			$tpl->setVariable("FILE", substr($file, $len));
			$tpl->parseCurrentBlock();
			
			if ("class_" == substr($file, $len, 6)) {

				$renderer->render(substr($file, $len), "class");

			} else if ("module_" == substr($file, $len, 7)) {

				$renderer->render(substr($file, $len), "module");

			} else if ("classtree_" == substr($file, $len, 10)) {
			
				$renderer->render(substr($file, $len), "classtree");
				
			}	else if ("modulegroup_" ==  substr($file, $len, 12)) {
			 
				$renderer->render(substr($file, $len), "modulegroup");
				
			} else if ("warnings_" == substr($file, $len, 9)) {
			
				$renderer->render(substr($file, $len), "warning");
				
			}
			
		}
	
		$renderer->finish();	
		$fileHandler->createFile($target."phpdoc_xmlfiles.html", $tpl->get());
		
		$this->outl($this->finishInstructions);
		return true;
	} // end func	render
	
} // end class Phpdoc
?>