d123c65ddf4a29e7b34988254965aa3e89d4a4fc
[atutor.git] / mods / phpdoc / PHPDoc / xmlexporter / PhpdocXMLClassExporter.php
1 <?php\r
2 /**\r
3 * Exports the data of a class as an xml file.\r
4 *\r
5 * @version      $Id: PhpdocXMLClassExporter.php,v 1.2 2000/12/03 22:37:38 uw Exp $\r
6 */\r
7 class PhpdocXMLClassExporter extends PhpdocXMLDocumentExporter {\r
8 \r
9         /**\r
10         * Variable container attributes.\r
11         * @var  array   $variableAttributes\r
12         */                                                                                                              \r
13         var $variableAttributes = array(\r
14                                                                                                                                         "name"                  => "CDATA",\r
15                                                                                                                                         "access"                => "CDATA",\r
16                                                                                                                                         "type"                  => "CDATA",\r
17                                                                                                                                         "abstract"      => "Boolean",\r
18                                                                                                                                         "static"                => "Boolean",\r
19                                                                                                                                         "final"                 => "Boolean"\r
20                                                                                                                                 );              \r
21         /**\r
22         * Class container attributes.\r
23         * @var  array   $classAttributes\r
24         */\r
25         var $classAttributes = array(   \r
26                                                                                                                                 "name"                  => "CDATA",\r
27                                                                                                                                 "extends"               => "CDATA",\r
28                                                                                                                                 "undoc"                 => "Boolean",\r
29                                                                                                                                 "access"                => "CDATA",\r
30                                                                                                                                 "abstract"      => "Boolean",\r
31                                                                                                                                 "static"                => "Boolean",\r
32                                                                                                                                 "final"                 => "Boolean",\r
33                                                                                                                                 "package"               => "CDATA"\r
34                                                                                                         );\r
35 \r
36         var     $fileprefix = "class_";\r
37         \r
38         function PhpdocXMLClassExporter() {\r
39                 $this->PHPDocXMLExporter();\r
40         } // end constructor\r
41         \r
42         function create() {\r
43                 \r
44                 $attribs = $this->getAttributes($this->result, $this->classAttributes);                                                                         \r
45                 $this->xmlwriter->startElement("class", "", $attribs, false);\r
46                 \r
47                 $this->filenameXML($this->result["filename"]);\r
48                 \r
49                 $this->docXML($this->result);   \r
50                 \r
51                 if (isset($this->result["functions"]))\r
52                         $this->functionsXML($this->result["functions"]);\r
53                         \r
54                 if (isset($this->result["variables"]))\r
55                         $this->variablesXML($this->result["variables"]);\r
56                         \r
57                 if (isset($this->result["uses"]))\r
58                         $this->usesXML($this->result["uses"]);\r
59                         \r
60                 if (isset($this->result["consts"]))\r
61                         $this->constsXML($this->result["consts"]);\r
62                         \r
63                 if (isset($this->result["inherited"]))\r
64                         $this->inheritedOverridenXML($this->result["inherited"], "inherited");\r
65                         \r
66                 if (isset($this->result["overriden"]))\r
67                         $this->inheritedOverridenXML($this->result["overriden"], "overriden");\r
68                         \r
69                 if (isset($this->result["path"]))\r
70                         $this->pathXML($this->result["path"]);\r
71                 \r
72                 if (isset($this->result["baseclass"]))\r
73                         $this->baseclassXML($this->result["baseclass"]);\r
74                 \r
75                 if (isset($this->result["subclasses"]))\r
76                         $this->subclassesXML($this->result["subclasses"]);\r
77                         \r
78                 $this->xmlwriter->endElement("class", true);\r
79                 \r
80         } // end func create\r
81         \r
82         /**\r
83         * Handles inherited and overriden elements.\r
84         * \r
85         * @param        array           Array of inherited or overriden elements\r
86         * @param        string  Container used when saving the elements\r
87         */\r
88         function inheritedOverridenXML($data, $tag) {\r
89                 \r
90                 reset($data);\r
91                 while (list($type, $elements) = each($data)) {\r
92                 \r
93                         reset($elements);\r
94                         while (list($from, $data2) = each($elements)) {\r
95 \r
96                                 $attribs = $this->getAttributes( array ("type" => $type, "src" => $from), $this->inheritedOverridenAttributes);                         \r
97                                 $this->xmlwriter->startElement($tag, "", $attribs, false);\r
98                                 \r
99                                 reset($data2);\r
100                                 while (list($name, $v) = each($data2))\r
101                                         $this->xmlwriter->addElement("element", $name);\r
102                                         \r
103                                 $this->xmlwriter->endElement($tag, true);\r
104                                         \r
105                         }\r
106                         \r
107                 }\r
108                 \r
109         } // end func inheritedOverridenXML\r
110 \r
111         /**\r
112         * Writes the "path" (inheritance chain) of an element.\r
113         *\r
114         * @param        array\r
115         */      \r
116         function pathXML($path) {\r
117                 if (0 == count($path))\r
118                         return;\r
119                         \r
120                 $this->xmlwriter->startElement("path", "", "", false);                  \r
121                 \r
122                 reset($path);\r
123                 while (list($k, $parent) = each($path)) \r
124                         $this->xmlwriter->addElement("parent", $parent);\r
125                 \r
126                 $this->xmlwriter->endElement("path", true);\r
127                 \r
128         } // end func pathXML\r
129         \r
130         /**\r
131         * Adds a baseclass container to the generated xml.\r
132         *\r
133         * @param        string  Name of the baseclass\r
134         */\r
135         function baseclassXML($base) {\r
136         \r
137                 if ("" != $base)\r
138                         $this->xmlwriter->addElement("baseclass", $base);\r
139                         \r
140         } // end func baseclassXML\r
141         \r
142         /**\r
143         * Adds a list of subclasses to the generated xml.\r
144         *\r
145         * @param        array   \r
146         */\r
147         function subclassesXML($subclasses) {\r
148                 if (0 == count($subclasses))\r
149                         return;\r
150                 \r
151                 $this->xmlwriter->startElement("subclasses", "", "", false, true);      \r
152                 \r
153                 reset($subclasses);\r
154                 while(list($subclass, $v) = each($subclasses)) \r
155                         $this->xmlwriter->addElement("subclass", $subclass);\r
156                 \r
157                 $this->xmlwriter->endElement("subclasses", true);\r
158                 \r
159         } // end func subclassesXML\r
160         \r
161         /**\r
162         * Adds class variables to the XMl document.\r
163         *\r
164         * @param        array\r
165         */\r
166         function variablesXML($variables) {\r
167                                                                                                                         \r
168                 reset($variables);\r
169                 while (list($variable, $data) = each($variables)) {\r
170                 \r
171                         $attribs = $this->getAttributes($data, $this->variableAttributes);\r
172                         $this->xmlwriter->startElement("variable", $data["value"], $attribs, false);\r
173                         $this->docXML($data);\r
174                         $this->xmlwriter->endElement("variable", true);\r
175                         \r
176                 }\r
177                 \r
178         } // end func variablesXML\r
179         \r
180 } // end class PhpdocXMLClassExporter\r
181 ?>