6e93a87df8a9d43bb88e27ec6e66848e78b926a0
[atutor.git] / mods / phpdoc / PHPDoc / xmlexporter / PhpdocXMLDocumentExporter.php
1 <?php\r
2 /**\r
3 * Base of the class and module exporter.\r
4\r
5 * @version $Id: PhpdocXMLDocumentExporter.php,v 1.2 2000/12/03 22:37:38 uw Exp $\r
6 */\r
7 class PhpdocXMLDocumentExporter extends PhpdocXMLExporter {\r
8         \r
9         /**\r
10         * Mapping from internal result array index name to xml tag name.\r
11         *\r
12         * @var  array   $docTags\r
13         */\r
14         var $docTags = array(\r
15                                                                                                 "desc"                  => "description",\r
16                                                                                                 "sdesc"                 => "shortdescription",\r
17                                                                                                 \r
18                                                                                                 "version"               => "version",\r
19                                                                                                 "since"                 => "since",\r
20                                                                                                 "version"               => "version",\r
21                                                                                                 "deprec"                => "deprecated",\r
22                                                                                                 "copyright"     => "copyright",\r
23                                                                                                 "exclude"               => "exclude",\r
24                                                                                                 "brother"               => "brother",\r
25                                                                                                 "magic"                 => "magic"\r
26                                                                                         );\r
27 \r
28         /**\r
29         * Attributes of the <see> container.\r
30         *\r
31         * @var  array   $seeAttributes\r
32         */                                                                                      \r
33         var $seeAttributes = array(\r
34                                                                                                                         "type"  => "CDATA",\r
35                                                                                                                         "group" => "CDATA"\r
36                                                                                                                 );\r
37         \r
38         /**\r
39         * Attributes of the <link> container.\r
40         *\r
41         * @var  array   $linkAttributes\r
42         */\r
43         var $linkAttributes = array( "url"      => "CDATA" );\r
44 \r
45         /**\r
46         * Attributes of the <author> container.\r
47         *\r
48         * @var  array   $authorAttributes\r
49         */                                                                                                              \r
50         var $authorAttributes = array( "email"  => "CDATA" );\r
51                                                                                                                         \r
52         /**\r
53         * Attributes of <inherited> and <overriden> container.\r
54         *\r
55         * @var  array   $inheritedOverridenAttributes\r
56         */                                                                                                                      \r
57         var $inheritedOverridenAttributes = array(\r
58                                                                                                                                                         "src"           => "CDATA",\r
59                                                                                                                                                         "type"  => "CDATA"\r
60                                                                                                                                         );                                                                      \r
61 \r
62         /**\r
63         * Attributes of the <constant> container.\r
64         *\r
65         * @var  array   $constAttributes        \r
66         */                                                                                                                                                              \r
67         var $constAttributes = array(\r
68                                                                                                                                 "name"          => "CDATA",\r
69                                                                                                                                 "undoc"         => "Boolean",\r
70                                                                                                                                 "access"        => "CDATA",\r
71                                                                                                                                 "case"          => "CDATA"\r
72                                                                                                                         );\r
73 \r
74         /**\r
75         * Attribues of the <uses> container.\r
76         *\r
77         * @var  array   $usesAttributes\r
78         */                                                                                                                      \r
79         var $usesAttributes = array(\r
80                                                                                                                                 "type"  => "CDATA",\r
81                                                                                                                                 "file"  => "CDATA",\r
82                                                                                                                                 "undoc" => "Boolean"\r
83                                                                                                                 );\r
84                                                                                                         \r
85         /**\r
86         * Attribues of the <function> container.\r
87         *\r
88         * @var  array   $functionAttributes\r
89         */                                                                                                              \r
90         var $functionAttributes = array(\r
91                                                                                                                                         "name"                  => "CDATA",\r
92                                                                                                                                         "undoc"                 => "Boolean",\r
93                                                                                                                                         "access"                => "CDATA",\r
94                                                                                                                                         "abstract"      => "Boolean",\r
95                                                                                                                                         "static"                => "CDATA"\r
96                                                                                                                                 );\r
97 \r
98         /**\r
99         * Attributes of the <return> container.\r
100         *\r
101         * @var  array   $returnAttributes\r
102         */                                                                                                                              \r
103         var $returnAttributes = array( \r
104                                                                                                                                 "name"  => "CDATA",\r
105                                                                                                                                 "type"  => "CDATA"\r
106                                                                                                                         );                      \r
107 \r
108         /**\r
109         * Attributes of the <global> container.\r
110         *\r
111         * @var  array   $globalAttributes\r
112         */                                                                                                                      \r
113         var $globalAttributes = array(\r
114                                                                                                                                 "name"  => "CDATA",\r
115                                                                                                                                 "type"  => "CDATA"\r
116                                                                                                                         );                      \r
117 \r
118         /**\r
119         * Attributes of the <param> container.\r
120         *\r
121         * @var  array   $paramAttributes\r
122         */                                                                                                                      \r
123         var $paramAttributes    = array(\r
124                                                                                                                                 "name"          => "CDATA",\r
125                                                                                                                                 "default"       => "CDATA",\r
126                                                                                                                                 "type"          => "CDATA",\r
127                                                                                                                                 "undoc"         => "Boolean"\r
128                                                                                                                         );      \r
129         \r
130         /**\r
131         * Writes a <file> container.\r
132         *\r
133         * @param        string  $file   filename\r
134         */\r
135         function filenameXML($file) {\r
136                 $this->xmlwriter->addElement("file", $file);\r
137         } // end func filenameXML\r
138         \r
139         /**\r
140         * Adds all constants (define(), const) to the xml document.\r
141         *\r
142         * @param        array           Array of constants\r
143         * @return       boolean Returns false on failure otherwise true\r
144         */\r
145         function constsXML($consts) {\r
146                 if (!is_array($consts) || 0 == count($consts)) \r
147                         return true;\r
148         \r
149                 reset($consts);\r
150                 while (list($k, $data)=each($consts)) {\r
151                 \r
152                         $attribs = $this->getAttributes($data, $this->constAttributes);\r
153                         $this->xmlwriter->startElement("constant", (isset($data["value"])) ? $data["value"] : "", $attribs, false, true);\r
154                         $this->docXML($data);\r
155                         $this->xmlwriter->endElement("constant", true);\r
156                         \r
157                 }\r
158                 \r
159                 return true;\r
160         } // end func constsXML\r
161         \r
162         /**\r
163         * Adds a list of used files (include, require...) to the xml document.\r
164         * \r
165         * @param        array\r
166         */\r
167         function usesXML($uses) {\r
168                 if (!is_array($uses)) {\r
169                         $this->err[] = new PhpdocError("No array given.", __FILE__, __LINE__);\r
170                         return false;\r
171                 }\r
172         \r
173                 reset($uses);\r
174                 while (list($k, $data) = each($uses)) {\r
175                 \r
176                         $attribs = $this->getAttributes($data, $this->usesAttributes);\r
177                         $this->xmlwriter->startElement("uses", "", $attribs, false, true);\r
178                         $this->docXML($data);   \r
179                         $this->xmlwriter->endElement("uses", true);\r
180                         \r
181                 }\r
182                 \r
183                 return true;\r
184         } // end func usesXML\r
185         \r
186         /**\r
187         * Adds a list of functions to the xml file.\r
188         * \r
189         * @param        array\r
190         */\r
191         function functionsXML($functions) {\r
192                 if (!is_array($functions)) {\r
193                         $this->err[] = new PhpdocError("No array given.", __FILE__, __LINE__);\r
194                         return false;\r
195                 }\r
196 \r
197                 reset($functions);\r
198                 while (list($k, $data) = each($functions)) {\r
199                 \r
200                         $attribs = $this->getAttributes($data, $this->functionAttributes);                                      \r
201                         $this->xmlwriter->startElement("function", "", $attribs, false, true);\r
202                         $this->docXML($data);           \r
203                         $this->xmlwriter->endElement("function", true);\r
204                         \r
205                 }\r
206                                                                                                                         \r
207         } // end functionsXML\r
208         \r
209         /**\r
210         * Adds a documentation block (author, links, see, params...) to the xml document\r
211         * \r
212         * @param        array\r
213         */\r
214         function docXML($data) {\r
215                 \r
216                 $this->xmlwriter->startElement("doc", "", "", false, true);\r
217                 \r
218                 if (isset($data["link"]))\r
219                         $this->linkXML($data["link"]);          \r
220                 \r
221                 if (isset($data["author"]))\r
222                         $this->authorXML($data["author"]);\r
223                         \r
224                 if (isset($data["see"]))\r
225                         $this->seeXML($data["see"]);\r
226                         \r
227                 if (isset($data["params"]))\r
228                         $this->paramsXML($data["params"]);\r
229                         \r
230                 if (isset($data["return"]))\r
231                         $this->returnXML($data["return"]);\r
232                         \r
233                 if (isset($data["throws"])) \r
234                         $this->throwsXML($data["throws"]);\r
235                 \r
236                 if (isset($data["global"]))\r
237                         $this->globalsXML($data["global"]);\r
238 \r
239                 if (isset($data["inherited"])) {\r
240                         \r
241                         \r
242                         $attribs = array(\r
243                                                                                                 "src"   => array(\r
244                                                                                                                                                                         "type"  => $this->inheritedOverridenAttributes["src"],\r
245                                                                                                                                                                         "value" => $data["inherited"]\r
246                                                                                                                                                                 )\r
247                                                                                         );\r
248                         $this->xmlwriter->addElement("inherited", "", $attribs);\r
249                 }\r
250                 \r
251                 if (isset($data["overrides"])) {\r
252                         $attribs = array( \r
253                                                                                                 "src"   => array(\r
254                                                                                                                                                                         "type"  => $this->inheritedOverridenAttributes["src"],\r
255                                                                                                                                                                         "value" => $data["overrides"]\r
256                                                                                                                                                                 )\r
257                                                                                         );\r
258                         $this->xmlwriter->addElement("overriden", "", $attribs);                                                                                        \r
259                 }\r
260                         \r
261                 reset($this->docTags);\r
262                 while (list($field, $tag) = each($this->docTags))\r
263                         if (isset($data[$field]))\r
264                                 $this->xmlwriter->addElement($tag, $data[$field], "");\r
265                         \r
266                 $this->xmlwriter->endElement("doc", true);\r
267         } // end func docXML\r
268 \r
269         /**\r
270         * Adds <global> container to the xml document.\r
271         * \r
272         * @param array\r
273         */\r
274         function globalsXML($globals) {\r
275         \r
276                 reset($globals);\r
277                 while (list($k, $data) = each($globals)) {\r
278                         $attribs = $this->getAttributes($data, $this->globalAttributes);\r
279                         $this->xmlwriter->addElement("global", (isset($data["desc"])) ? $data["desc"] : "", $attribs);\r
280                 }\r
281                 \r
282         } // end func globalsXML\r
283         \r
284         /**\r
285         * Adds <throws> container to the xml document.\r
286         * \r
287         * @param        array\r
288         */\r
289         function throwsXML($exceptions) {\r
290                 \r
291                 reset($exceptions);\r
292                 while (list($k, $exception) = each($exceptions)) \r
293                         $this->xmlwriter->addElement("throws", $exception, "", true);\r
294                 \r
295         } // end func throwsXML\r
296         \r
297         /**\r
298         * Adds <return> container to the xml document.\r
299         * \r
300         * @param        array\r
301         */\r
302         function returnXML($return) {\r
303 \r
304                 $desc = "";     \r
305                 \r
306                 if (is_array($return)) {\r
307                 \r
308                         if (isset($return["desc"])) {\r
309                                 $desc = $return["desc"];\r
310                                 unset($return["desc"]);\r
311                         }\r
312                         $attribs = $this->getAttributes($return, $this->returnAttributes);\r
313                         \r
314                 } else {\r
315                 \r
316                         $attribs["type"] = array( "type"        => "CDATA", "value"     => $return );\r
317                         \r
318                 }\r
319                 \r
320                 $this->xmlwriter->addElement("return", $desc, $attribs);\r
321                 \r
322         } // end func returnXML \r
323         \r
324         /**\r
325         * Adds <parameter> container to the xml document.\r
326         * \r
327         * @param        array\r
328         */\r
329         function paramsXML($params) {\r
330         \r
331                 reset($params);\r
332                 while (list($k, $data) = each($params)) {\r
333                         $attribs = $this->getAttributes($data, $this->paramAttributes);\r
334                         $this->xmlwriter->addElement("parameter", (isset($data["desc"])) ? $data["desc"] : "", $attribs);\r
335                 }\r
336 \r
337         } // end func paramsXML\r
338         \r
339         /**\r
340         * Adds <author> container to the xml document.\r
341         *\r
342         * @param        array\r
343         */\r
344         function authorXML($authors) {\r
345                 \r
346                 reset($authors);\r
347                 while (list($k, $data) = each($authors)) {\r
348                         \r
349                         $attribs = array();\r
350                         \r
351                         if (isset($data["mail"]))\r
352                                 $attribs = array(\r
353                                                                                                         "email" => array(\r
354                                                                                                                                                                                 "type"  => $this->authorAttributes["email"],\r
355                                                                                                                                                                                 "value" => $data["mail"]\r
356                                                                                                                                                                         )\r
357                                                                                                 );\r
358                         $this->xmlwriter->addElement("author",$data["name"], $attribs);\r
359                                                                                                                                                         \r
360                 }\r
361                         \r
362         } // end func authorXML\r
363         \r
364         /**\r
365         * Adds <link> container to the xml document.\r
366         *\r
367         * @param        array\r
368         */\r
369         function linkXML($links) {\r
370                 \r
371                 reset($links);\r
372                 while (list($k, $data) = each($links)) {\r
373                 \r
374                         $attribs = array(\r
375                                                                                                 "url"   => array(\r
376                                                                                                                                                                         "type"  => $this->linkAttributes["url"],\r
377                                                                                                                                                                         "value" => $data["url"]\r
378                                                                                                                                                                 )\r
379                                                                                         );\r
380                         $this->xmlwriter->addElement("link",  (isset($data["desc"])) ? $data["desc"] : "", $attribs);                                                                                           \r
381                         \r
382                 }\r
383                 \r
384         } // end func linkXML\r
385         \r
386         /**\r
387         * Adds <see> container to the xml document.\r
388         * \r
389         * @param        array\r
390         */\r
391         function seeXML($see) {\r
392                 \r
393                 reset($see);\r
394                 while (list($type, $data) = each($see)) {\r
395                         \r
396                         reset($data);\r
397                         while (list($k, $data2) = each($data)) {\r
398                         \r
399                                 $attribs = array(\r
400                                                                                                         "type"  => array(\r
401                                                                                                                                                                                 "type"  => $this->seeAttributes["type"],\r
402                                                                                                                                                                                 "value" => strtolower($type)\r
403                                                                                                                                                                         )\r
404                                                                                                 );\r
405                                 if (isset($data2["group"]))\r
406                                         $attribs["group"] = array(\r
407                                                                                                                                                 "type"  => $this->seeAttributes["group"],\r
408                                                                                                                                                 "value" => $data2["group"]\r
409                                                                                                                                         );\r
410                                                                                                                                         \r
411                                 $this->xmlwriter->addElement("see", $data2["name"], $attribs);\r
412                                 \r
413                         }\r
414                                                                                                                 \r
415                 }\r
416                 \r
417         } // end func SeeXML\r
418 \r
419 } // end class PhpdocXMLDocumentExporter\r
420 ?>