c84d947fc4d85c2b7f1166bfbcd4f6efce69529a
[atutor.git] / mods / phpdoc / PHPDoc / accessor / PhpdocDocumentAccessor.php
1 <?php
2 /**
3 * Base of the class and module accessor.
4 */
5 class PhpdocDocumentAccessor extends PhpdocAccessor {
6
7         /**
8         * Kind of top-level container in the xml document.
9         * 
10         * Must be set by all derived classes.
11         *
12         * @var  string  
13         */
14         var $xmlkey = "";
15
16         /**
17         * Returns an array with all functions.
18         *
19         * @return array $functions
20         * @access       public
21         * @see  getFunctionsByAccess()
22         */
23         function getFunctions() {
24                 return $this->getElements("functions", "functionsaccess");
25         } // end func getFunctions
26         
27         /**
28         * Returns an array with all functions with a certain access (public, private) attribute.
29         *
30         * @param        string  Requested access attribute.
31         * @return       array   $functions
32         * @access       public
33         * @see  getFunctions()
34         */
35         function getFunctionsByAccess($access) {
36                 return $this->getElementsByAccess($access, "functions", "functionsaccess");
37         } // end func getFunctionByAccess
38         
39         /**
40         * Returns an array with all variables.
41         *
42         * @return       array $variables
43         * @access       public
44         * @see  getVariablesByAccess()
45         */
46         function getVariables() {
47                 return $this->getElements("variables", "variablesaccess");
48         } // end func getVariables
49
50         /**
51         * Returns an array with all variables with a certain access (public, private) attribute.
52         *
53         * @param        string  Requested access attribute.
54         * @return       array   $variables
55         * @access       public
56         * @see  getVariables()
57         */      
58         function getVariablesByAccess($access) {
59                 return $this->getElementsByAccess($access, "variables", "variablesaccess");
60         } // end func getVariablesByAccess
61         
62         /**
63         * Returns an array of all constants.
64         *
65         * @return       array   $constants
66         * @access       public
67         * @see  getConstantsByAccess()
68         */
69         function getConstants() {
70                 return $this->getElements("constants", "constantsaccess");
71         } // end func getConstants
72         
73         /**
74         * Returns an array of all constants with a certain access (public, private) attribute.
75         *
76         * @param        string  Requested access attribute.
77         * @return       array   $constants
78         * @see          getConstants()
79         * @access       public
80         */
81         function getConstantsByAccess($access) {
82                 return $this->getElementsByAccess($access, "constants", "constantsaccess");
83         } // end func getConstantsByAccess
84         
85         /**
86         * Returns an array of all included files.
87         *
88         * @return       array   $uses
89         * @see          getUsesByType()
90         * @access       public
91         */
92         function getUses() {
93                 return $this->getElements("uses", "usestype");
94         } // end func getUses
95
96         /**
97         * Returns an array of all included files with a certain type (include, require...) attribute.
98         *
99         * @param        string  Requested type: include, include_once, require, require_once
100         * @return       array           $uses
101         * @access       public
102         */      
103         function getUsesByType($type) {
104                 
105                 $data = array();
106                 
107                 if (!isset($this->data["usestype"][$type])) 
108                         return $data;
109                         
110                 reset($this->data["usestype"][$type]);
111                 while (list($k, $file)=each($this->data["usestype"][$type])) {
112                 
113                         $data[$file] = $this->data["uses"][$file];
114                         if ($this->freeOnGet)
115                                 unset($this->data["uses"][$file]);
116                                 
117                 }
118                 
119                 if ($this->freeOnGet)
120                         unset($this->data["usestype"][$type]);
121                         
122                 return $data;
123         } // end func getUsesByType
124         
125         /**
126         * Returns elements from the internal $data array.
127         * 
128         * The object uses this function to extract functions, variables, uses and 
129         * constants from an internal array. Note that this is not a public function,
130         * future version might access internal data structures different.
131         *
132         * @param        string  Name of the element you need: functions, variables,...
133         * @param        string  Name of internal element access table
134         * @see          $data
135         */
136         function getElements($element, $elementaccess) {
137                 
138                 if ($this->freeOnGet) {
139                         
140                         $data = $this->data[$element];
141                         unset($this->data[$element]);
142                         unset($this->data[$elementaccess]);
143                         return $data;
144                         
145                 } else {
146                 
147                         $this->data[$element];
148                         
149                 }
150                 
151         } // end func getElements
152
153         /**
154         * Returns elements with a certain access type from the internal data.
155         * @param        string  Accesstype
156         * @param        string  element name
157         * @param        string  access type
158         * @brother      getElements()
159         */      
160         function getElementsByAccess($access, $element, $elementaccess) {
161                 
162                 $data = array();
163                 
164                 if (!isset($this->data[$elementaccess][$access]))
165                         return $data;
166                 
167                 reset($this->data[$elementaccess][$access]);
168                 while (list($k, $name)=each($this->data[$elementaccess][$access])) {
169                         
170                         $data[$name] = $this->data[$element][$name];
171                         if ($this->freeOnGet)
172                                 unset($this->data[$element][$name]);
173                                 
174                 }
175                 
176                 if ($this->freeOnGet)
177                         unset($this->data[$elementaccess][$access]);
178                         
179                 return $data;
180         } // end func getElementsByAccess
181
182         /**
183         * Adds a list of included files to the internal data array.
184         */
185         function buildUseslist() {
186
187                 $this->data["uses"] = array();
188                 $this->data["usestype"] = array();
189                 
190                 if (isset($this->xml[$this->xmlkey]["uses"])) {
191
192                         if (isset($this->xml[$this->xmlkey]["uses"][0])) {              
193         
194                                 reset($this->xml[$this->xmlkey]["uses"]);
195                                 while (list($k, $data)=each($this->xml[$this->xmlkey]["uses"])) {
196                                         $this->data["uses"][$data["file"]] = $data;
197                                         $this->data["usestype"][$data["type"]][] = $data["file"];
198                                 } 
199                                 
200                         } else {
201                         
202                                 $data = $this->xml[$this->xmlkey]["uses"];
203                                 $this->data["uses"][$data["file"]] = $data;
204                                 $this->data["usestype"][$data["type"]][] = $data["file"];
205
206                         }
207                         
208                         unset($this->xml[$this->xmlkey]["uses"]);                       
209                 }
210                 
211         } // end func buildUseslist
212         
213         /**
214         * Adds a list of a certain element to the internal data array.
215         *
216         * @param        string  name of the element to add: function, variable, constant.
217         */
218         function getElementlist($element) {
219         
220                 $elements = array();
221                 $elementaccess = array();
222                 
223                 if (isset($this->xml[$this->xmlkey][$element])) {
224                                                                                                                         
225                         if (isset($this->xml[$this->xmlkey][$element][0])) {
226
227                                 reset($this->xml[$this->xmlkey][$element]);
228                                 while (list($k, $data)=each($this->xml[$this->xmlkey][$element])) {
229                                         $elements[$data["name"]] = $data;
230                                         $elementaccess[$data["access"]][] = $data["name"];      
231                                 }       
232                                 
233                         } else {
234                                 
235                                 $data = $this->xml[$this->xmlkey][$element];
236                                 $elements[$data["name"]] = $data;
237                                 $elementaccess[$data["access"]][] = $data["name"];
238                                 
239                         }
240                         
241                         unset($this->xml[$this->xmlkey][$element]);
242                         
243                 }
244                 
245                 return array($elements, $elementaccess);
246         } // end func getElementlist
247
248 } // end class PhpdocDocumentAccessor
249 ?>