changed git call from https to git readonly
[atutor.git] / mods / phpdoc / PHPDoc / accessor / PhpdocClassAccessor.php
1 <?php\r
2 /**\r
3 * Provides functions to access phpdoc xml documents that contain classes.\r
4 *\r
5 * @author               Ulf Wendel <ulf.wendel@phpdoc.de>\r
6 * @version      1.0     \r
7 * @package      PHPDoc\r
8 */\r
9 class PhpdocClassAccessor extends PhpdocDocumentAccessor {\r
10 \r
11         var $xmlkey = "class";\r
12         \r
13         /**\r
14         * Array of inherited elements\r
15         * @var  array   $inherited\r
16         */      \r
17         var $inherited = array();\r
18         \r
19         /**\r
20         * Returns an array with the data of a class (no functions etc, just the class docs).\r
21         * @return       array   $class\r
22         * @access       public\r
23         */\r
24         function getClassdata() {\r
25                 \r
26                 $class = $this->xml["class"];\r
27 \r
28                 unset($class["variable"]);\r
29                 unset($class["function"]);\r
30                 unset($class["uses"]);\r
31                 unset($class["constant"]);\r
32                 unset($class["inherited"]);\r
33                 unset($class["overriden"]);\r
34                 unset($class["path"]);\r
35                 \r
36                 return $class;\r
37         } // end func getClassdata\r
38         \r
39         /**\r
40         * Returns an array of inherited functions.\r
41         * @return       array   \r
42         * @access       public\r
43         * @see  getInheritedVariables(), getInheritedUses(), getInheritedConstants()\r
44         */\r
45         function getInheritedFunctions() {\r
46                 return $this->inherited["functions"];\r
47         } // end func getInheritedFunctions\r
48 \r
49         /**\r
50         * Returns an array of inherited variables.\r
51         * @return       array\r
52         * @access       public\r
53         * @see  getInheritedFunctions(), getInheritedUses(), getInheritedConstants()\r
54         */      \r
55         function getInheritedVariables() {\r
56                 return $this->inherited["variables"];\r
57         } // end func getInheritedVariables\r
58         \r
59         /**\r
60         * Returns an array of inherited included files.\r
61         * @return       array\r
62         * @access       public\r
63         * @see          getInheritedFunctions(), getInheritedUses(), getInheritedConstants()\r
64         */\r
65         function getInheritedUses() {\r
66                 return $this->inherited["uses"];\r
67         } // end func getInheritedUses()\r
68         \r
69         /**\r
70         * Returns an array of inherited constants.\r
71         * @return       array\r
72         * @access       public\r
73         * @see          getInheritedFunctions(), getInheritedVariables(), getInheritedUses()\r
74         */\r
75         function getInheritedConstants() {\r
76                 return $this->inherited["constants"];\r
77         } // end func getInheritedConstants\r
78         \r
79         /**\r
80         * Returns an array with the "path" of a class.\r
81         * @return array $path\r
82         * @access       public\r
83         * @see          getSubclasses()\r
84         */      \r
85         function getClasstree() {\r
86                 \r
87                 if (isset($this->xml["class"]["path"]))\r
88                         return $this->convertPath($this->xml["class"]["path"]);\r
89                 else \r
90                         return array();\r
91                         \r
92         } // end func getClasstree\r
93         \r
94         /**\r
95         * Returns an array with all subclasses of a class.\r
96         * @return       array\r
97         * @access       public\r
98         * @see          getClasstree()\r
99         */\r
100         function getSubclasses() {\r
101                 return $this->data["subclasses"];\r
102         } // end func getSubclasses\r
103         \r
104 \r
105         /**\r
106         * Converts a xml path array to a path that can be passed to the user.\r
107         * \r
108         * The path is an array like path[0..n] = classname where path[0] is the \r
109         * directs parent (extends path[0]) and path[n] is the baseclass.\r
110         *\r
111         * @param        array   $xmlpath\r
112         * @return       array   $path\r
113         */\r
114         function convertPath($xmlpath) {\r
115 \r
116                 $path = array();\r
117                 \r
118                 if (!isset($xmlpath["parent"][0])) {\r
119                         \r
120                         $path[0] = $xmlpath["parent"]["value"];         \r
121                                 \r
122                 } else {\r
123                 \r
124                         reset($xmlpath["parent"]);\r
125                         while (list($k, $parent)=each($xmlpath["parent"]))\r
126                                 $path[] = $parent["value"];\r
127                                 \r
128                 }\r
129 \r
130                 return $path;\r
131         } // end func convertPath\r
132         \r
133         /**\r
134         * Builds a list of inherited elements.\r
135         * @see  $inherited\r
136         */\r
137         function buildInheritedlist() {\r
138                 \r
139                 $this->inherited = array(\r
140                                                                                                                         "functions"     => array(),\r
141                                                                                                                         "variables"     => array(),\r
142                                                                                                                         "constants"     => array(),\r
143                                                                                                                         "uses"                  => array()\r
144                                                                                                                 );\r
145                         \r
146                 if (isset($this->xml["class"]["inherited"])) {\r
147 \r
148                         if (isset($this->xml["class"]["inherited"][0])) {\r
149                         \r
150                                 reset($this->xml["class"]["inherited"]);\r
151                                 while (list($k, $inherited)=each($this->xml["class"]["inherited"])) {\r
152                                                 \r
153                                         $type = $inherited["type"];\r
154                                         $src    = $inherited["src"];\r
155                 \r
156                                         if (isset($inherited["element"][0])) {\r
157                                         \r
158                                                 reset($inherited["element"]);\r
159                                                 while (list($k2, $element)=each($inherited["element"])) \r
160                                                         $this->inherited[$type][$src][] = $element["value"];\r
161                                                         \r
162                                         }       else {\r
163                                         \r
164                                                 $this->inherited[$type][$src][] = $inherited["element"]["value"];\r
165                                                 \r
166                                         }\r
167                                         \r
168                                 }\r
169                         \r
170                         }       else {\r
171                                 \r
172                                 $inherited = $this->xml["class"]["inherited"];\r
173                                 $type                    = $inherited["type"];\r
174                                 $src                     = $inherited["src"];\r
175                                 \r
176                                 if (isset($inherited["element"][0])) {\r
177                                         \r
178                                         reset($inherited["element"]);\r
179                                         while (list($k, $element)=each($inherited["element"])) \r
180                                                 $this->inherited[$type][$src][] = $element["value"];\r
181                                                 \r
182                                 } else {\r
183                                 \r
184                                         $this->inherited[$type][$src][] = $inherited["element"]["value"];\r
185                                         \r
186                                 }\r
187 \r
188                         }\r
189                         \r
190                         unset($this->xml["class"]["inherited"]);\r
191                         \r
192                 }\r
193                         \r
194         } // end func buildInheritedlist\r
195         \r
196         /**\r
197         * Builds a list of subclasses\r
198         */\r
199         function buildSubclasslist() {\r
200                 \r
201                 $this->data["subclasses"] = array();\r
202                 \r
203                 if (isset($this->xml["class"]["subclasses"])) {\r
204                 \r
205                         if (isset($this->xml["class"]["subclasses"]["subclass"][0])) {\r
206 \r
207                                 reset($this->xml["class"]["subclasses"]["subclass"]);\r
208                                 while (list($k, $subclass)=each($this->xml["class"]["subclasses"]["subclass"]))\r
209                                         $this->data["subclasses"][] = $subclass["value"];\r
210 \r
211                         } else {\r
212 \r
213                                 $this->data["subclasses"][] = $this->xml["class"]["subclasses"]["subclass"]["value"];\r
214                                 \r
215                         }\r
216 \r
217                 }\r
218                 \r
219         } // end func buildSubclasslist\r
220         \r
221         function init() {\r
222 \r
223                 #$this->introspection("xml", $this->xml);\r
224                 \r
225                 $this->buildInheritedlist();\r
226                 $this->buildSubclasslist();\r
227                 \r
228                 list($this->data["functions"], $this->data["functionsaccess"]) = $this->getElementlist("function");             \r
229                 list($this->data["variables"], $this->data["variablesaccess"]) = $this->getElementlist("variable");\r
230                 list($this->data["constants"], $this->data["constantsaccess"]) = $this->getElementlist("constant");\r
231                 \r
232                 $this->buildUseslist();         \r
233                 \r
234                 #$this->introspection("data", $this->data);\r
235 \r
236         } // end func Init\r
237         \r
238 } // end class PhpdocClassAccessor\r
239 ?>