3 /* vim: set binary expandtab tabstop=4 shiftwidth=4 foldmethod=marker:
4 -------------------------------------------------------------------------------
5 Created: jue jul 31 14:01:57 ART 2003
6 Author : Martin Marrese <m_marrese@argentina.com> <mmarre@mecon.gov.ar>
7 -------------------------------------------------------------------------------
9 -----------------------------------------------------------------------------*/
13 <?xml version="1.0" encoding="UTF-8"?>
14 <XMI xmlns:UML="org.omg/standards/UML" verified="false" timestamp="" xmi.version="1.2" >
21 <listitem open="1" type="800" id="-1" label="Views" >
22 <listitem open="1" type="801" id="-1" label="Logical View" >
26 <listitem open="1" type="802" id="-1" label="Use Case View" />
27 <listitem open="1" type="821" id="-1" label="Component View" />
28 <listitem open="1" type="827" id="-1" label="Deployment View" />
29 <listitem open="0" type="823" id="-1" label="Diagrams" />
37 $umlclass = '<UML:Class stereotype="##STEREOTYPE##" package="##PACKAGE##" xmi.id="##ID##" abstract="##ABSTRACT##" documentation="##DOCUMENTATION##" name="##NAME##" static="##STATIC##" scope="##SCOPE##" >';
38 $umlclass_c = '</UML:Class>';
40 $umloperation = '<UML:Operation stereotype="##STEREOTYPE##" package="##PACKAGE##" xmi.id="##ID##" type="##TYPE##" abstract="##ABSTRACT##" documentation="##DOCUMENTATION##" name="##NAME##" static="##STATIC##" scope="##SCOPE##">';
41 $umloperation_c = '</UML:Operation>';
43 $umlparameter = '<UML:Parameter stereotype="##STEREOTYPE##" package="##PACKAGE##" xmi.id="##ID##" value="##VALUE##" type="##TYPE##" abstract="##ABSTRACT##" documentation="##DOCUMENTATION##" name="##NAME##" static="##STATIC##" scope="##SCOPE##" />';
45 $umlattribute = '<UML:Attribute stereotype="##STEREOTYPE##" package="##PACKAGE##" xmi.id="##ID##" value="##VALUE##" type="##TYPE##" abstract="##ABSTRACT##" documentation="##DOCUMENTATION##" name="##NAME##" static="##STATIC##" scope="##SCOPE##" />';
47 $umllistitem = '<listitem open="0" type="##TYPE##" id="##ID##" label="##LABEL##" >';
48 $umllistitem_c = '</listitem>';
52 $IDPARAM = 0; //Functions parameter ID
53 $ARRAY = array(); //Array with information obtained from the code file
56 //GETTING DATA FROM FILES {{{
57 for ($j = 1; $j < count($argv); $j++) {
61 while (($f = readdir($dh)) !== false) {
62 if (is_readable("$file/$f") and substr($f, -4) == '.php') {
69 //PARSING INFORMATION {{{
70 elseif (is_readable($file) and substr($file, -4) == '.php') {
75 foreach ($cont as $line) {
77 $tmp = preg_split ('/[^\w_\/\*\@\$\&\.\']+/', $line);
79 if ($tmp['0'] == '/**') { //Starts documentation
81 $doc_param = 0; //If 1 the line belongs to a parameter documentation
83 if ($tmp['0'] == '*/') { //Ends documentation
88 //Parse documentation {{{
90 $tmp2 = ltrim ($line,'* /**'); //Removes * or /** from the beginning of the line
91 $action = substr($tmp2, 0, strpos($tmp2,' ')); //Gets the action (evrerything before the @)
92 $action = ($action === '') ? $tmp2 : $action;
93 $value = trim(strstr($tmp2, ' ')); //Action value
96 case '@access' : switch ($value) {
97 case 'private' : $options['access'] = 201;
99 case 'protected': $options['access'] = 202;
101 default : $options['access'] = 200;
105 case '@package' : $options['package'] = $value;
108 case '@abstract': $options['abstract'] = 1;
111 case '@static' : $options['static'] = 1;
114 case '@var' : $options['type'] = substr($value, 0, strpos($value,' '));
117 case '@return' : $type = substr($value, 0, strpos($value,' '));
118 $rest = (strpos($value,' ')) ? substr($value, strpos($value,' ')) : '';
122 if (strtolower($type) == 'object') {
124 $type = substr($rest, 0, strpos($rest,' '));
125 $rest = (strpos($rest,' ')) ? substr($rest, strpos($rest,' ')) : '';
127 $options['type'] = $type;
128 //If there is more documentation, I add it to the main documentation
130 $options['documentation'].= "Returns: ".trim($rest);
135 case '@param' : $cont_param++;
136 $type = substr($value, 0, strpos($value,' '));
137 $rest = substr($value, strpos($value,' ') + 1);
138 if (strtolower($type) == 'object') {
140 $type = substr($rest, 0, strpos($rest,' '));
141 $rest = substr($rest, strpos($rest,' ') + 1);
143 $options['param'][$cont_param]['type'] = $type;
144 $options['param'][$cont_param]['documentation'] = trim(substr(trim($rest), strpos(trim($rest), ' ')));
148 $tmp2 = str_replace('"', '"', $tmp2);
149 $tmp2 = str_replace('<', '<' , $tmp2);
150 $tmp2 = str_replace('>', '>' , $tmp2);
151 $tmp2 = str_replace('&', '&' , $tmp2);
153 $options['param'][$cont_param]['documentation'].= "\n".$tmp2;
156 @$options['documentation'].= $tmp2."\n";
163 if (!$DOCUMENTING && $tmp['0'] == 'class') {
166 $ARRAY[$ID]['id'] = $ID;
167 $ARRAY[$ID]['name'] = $tmp['1'];
168 $ARRAY[$ID]['stereotype'] = (@$options['stereotype']) ? $options['stereotype'] : '';
169 $ARRAY[$ID]['package'] = (@$options['package']) ? $options['package'] : '';
170 $ARRAY[$ID]['abstract'] = (@$options['abstract']) ? $options['abstract'] : 0;
171 $ARRAY[$ID]['documentation'] = (@$options['documentation']) ? $options['documentation'] : '';
172 $ARRAY[$ID]['static'] = (@$options['static']) ? $options['static'] : 0;
173 $ARRAY[$ID]['scope'] = (@$options['access']) ? $options['access'] : 200;
174 $ARRAY[$ID]['operations'] = array();
175 $ARRAY[$ID]['attributes'] = array();
180 if (!$DOCUMENTING && $tmp['0'] == 'function') {
183 if ($tmp['1']{0} == '&') {
184 $tmp['1'] = substr($tmp['1'], 1); //Removes the &
185 $options['type'] = (@$options['type']) ? '&'.$options['type'] : '';
188 if ($tmp['1']{0} == '_') {
189 $tmp['1'] = substr($tmp['1'], 1); //Removes the _
191 $ARRAY[$IDCLASS]['operations'][$ID]['id'] = $ID;
192 $ARRAY[$IDCLASS]['operations'][$ID]['name'] = $tmp['1'];
193 $ARRAY[$IDCLASS]['operations'][$ID]['stereotype'] = (@$options['stereotype']) ? $options['stereotype'] : '';
194 $ARRAY[$IDCLASS]['operations'][$ID]['package'] = (@$options['package']) ? $options['package'] : '';
195 $ARRAY[$IDCLASS]['operations'][$ID]['abstract'] = (@$options['abstract']) ? $options['abstract'] : 0;
196 $ARRAY[$IDCLASS]['operations'][$ID]['documentation'] = (@$options['documentation']) ? $options['documentation'] : '';
197 $ARRAY[$IDCLASS]['operations'][$ID]['static'] = (@$options['static']) ? $options['static'] : 0;
198 $ARRAY[$IDCLASS]['operations'][$ID]['scope'] = (@$options['access']) ? $options['access'] : 200;
199 $ARRAY[$IDCLASS]['operations'][$ID]['type'] = (@$options['type']) ? $options['type'] : '';
200 $ARRAY[$IDCLASS]['operations'][$ID]['param'] = array();
203 $param_line = trim(substr(strstr($line,'('),0),'{ '); //Removes the last {
204 $param = parseParenthesis($param_line);
206 foreach ($param as $par) {
207 if ($par['name']{0} == '$'|| $par['name']{0} == '&') { //If starts with $ or &
208 switch ($par['name']{0}) {
209 case '$': $par['name'] = substr($par['name'], 1); //Removes the $
211 case '&': $par['name'] = substr($par['name'], 2); //Removes the & and the $
212 $options['param'][$i]['type'] =
213 (@$options['param'][$i]['type']) ? '&'.$options['param'][$i]['type'] : '';
216 $ARRAY[$IDCLASS]['operations'][$ID]['param'][$i]['id'] = $i;
217 $ARRAY[$IDCLASS]['operations'][$ID]['param'][$i]['name'] = $par['name'];
218 $ARRAY[$IDCLASS]['operations'][$ID]['param'][$i]['stereotype'] =
219 (@$options['param'][$i]['stereotype']) ? $options['param'][$i]['stereotype'] : '';
221 $ARRAY[$IDCLASS]['operations'][$ID]['param'][$i]['package'] =
222 (@$options['param'][$i]['package']) ? $options['param'][$i]['package'] : '';
224 $ARRAY[$IDCLASS]['operations'][$ID]['param'][$i]['abstract'] =
225 (@$options['param'][$i]['abstract']) ? $options['param'][$i]['abstract'] : 0;
227 $ARRAY[$IDCLASS]['operations'][$ID]['param'][$i]['documentation'] =
228 (@$options['param'][$i]['documentation']) ? $options['param'][$i]['documentation'] : '';
230 $ARRAY[$IDCLASS]['operations'][$ID]['param'][$i]['static'] =
231 (@$options['param'][$i]['static']) ? $options['param'][$i]['static'] : 0;
233 $ARRAY[$IDCLASS]['operations'][$ID]['param'][$i]['scope'] =
234 (@$options['param'][$i]['access']) ? $options['param'][$i]['access'] : '';
236 $ARRAY[$IDCLASS]['operations'][$ID]['param'][$i]['type'] =
237 (@$options['param'][$i]['type']) ? $options['param'][$i]['type'] : '';
239 $ARRAY[$IDCLASS]['operations'][$ID]['param'][$i]['value'] =
240 (@$par['value']) ? $par['value'] : '';
251 if (!$DOCUMENTING && $tmp['0'] == 'var') {
253 $tmp['1'] = substr($tmp['1'], 1); //Removes the $
254 if ($tmp['1']{0} == '_') {
255 $tmp['1'] = substr($tmp['1'],1); //Removes the _
256 if (!(@$options['access'])) {
257 $options['access'] = 201;
260 //Check for default values
261 if (array_key_exists('2',$tmp)) {
262 $options['value'] = $tmp['2'];
265 $ARRAY[$IDCLASS]['attributes'][$ID]['id'] = $ID;
266 $ARRAY[$IDCLASS]['attributes'][$ID]['name'] = $tmp['1'];
267 $ARRAY[$IDCLASS]['attributes'][$ID]['stereotype'] = (@$options['stereotype']) ? $options['stereotype'] : '';
268 $ARRAY[$IDCLASS]['attributes'][$ID]['package'] = (@$options['package']) ? $options['package'] : '';
269 $ARRAY[$IDCLASS]['attributes'][$ID]['abstract'] = (@$options['abstract']) ? $options['abstract'] : 0;
270 $ARRAY[$IDCLASS]['attributes'][$ID]['documentation'] = (@$options['documentation']) ? $options['documentation'] : '';
271 $ARRAY[$IDCLASS]['attributes'][$ID]['static'] = (@$options['static']) ? $options['static'] : 0;
272 $ARRAY[$IDCLASS]['attributes'][$ID]['scope'] = (@$options['access']) ? $options['access'] : 200;
273 $ARRAY[$IDCLASS]['attributes'][$ID]['type'] = (@$options['type']) ? $options['type'] : '';
274 $ARRAY[$IDCLASS]['attributes'][$ID]['value'] = (@$options['value']) ? $options['value'] : '';
284 //WRITES XMI FILE {{{
285 $m =fopen ('./umlOut.xmi', 'w');
286 fwrite($m, $xmi_start);
289 foreach ($ARRAY as $ar) {
292 fwrite($m, preg_replace (array ('/##STEREOTYPE##/','/##PACKAGE##/','/##ID##/','/##ABSTRACT##/','/##DOCUMENTATION##/','/##NAME##/',
293 '/##STATIC##/','/##SCOPE##/'),
294 array ($ar['stereotype'],$ar['package'],$ar['id'],$ar['abstract'],trim($ar['documentation']),$ar['name'],
295 $ar['static'],$ar['scope']),
297 //Prepare class listitem line
298 $tmp2 = $umllistitem;
299 $LISTITEM.= preg_replace (array('/##TYPE##/','/##LABEL##/','/##ID##/'),array(813, $ar['name'], $ar['id']),$tmp2)."\n";
302 foreach ($ar['operations'] as $op) {
303 $tmp2 = $umloperation;
304 fwrite($m, preg_replace (array('/##STEREOTYPE##/','/##PACKAGE##/','/##ID##/','/##TYPE##/','/##ABSTRACT##/','/##DOCUMENTATION##/',
305 '/##NAME##/','/##STATIC##/','/##SCOPE##/'),
306 array($op['stereotype'],$op['package'],$op['id'],$op['type'],$op['abstract'],trim($op['documentation']),
307 $op['name'],$op['static'],$op['scope']) ,
310 //Parameters aren't listed in listview
311 foreach ($op['param'] as $pa) {
312 $tmp2 = $umlparameter;
313 fwrite ($m, preg_replace(array('/##STEREOTYPE##/','/##PACKAGE##/','/##ID##/','/##TYPE##/','/##ABSTRACT##/','/##DOCUMENTATION##/',
314 '/##NAME##/','/##STATIC##/','/##SCOPE##/','/##VALUE##/'),
315 array($pa['stereotype'],$pa['package'],$pa['id'],$pa['type'],$pa['abstract'],trim($pa['documentation']),
316 $pa['name'],$pa['static'],$pa['scope'],$pa['value']),
319 fwrite($m,$umloperation_c."\n");
320 //Pepare function lisitem line
321 $tmp2 = $umllistitem;
322 $LISTITEM.= preg_replace (array('/##TYPE##/','/##LABEL##/','/##ID##/'),array(815, $op['name'], $op['id']),$tmp2)."\n";
323 $LISTITEM.=$umllistitem_c."\n";
326 foreach ($ar['attributes'] as $op) {
327 $tmp2 = $umlattribute;
328 fwrite($m, preg_replace(array('/##STEREOTYPE##/','/##PACKAGE##/','/##ID##/','/##TYPE##/','/##ABSTRACT##/','/##DOCUMENTATION##/',
329 '/##NAME##/','/##STATIC##/','/##SCOPE##/','/##VALUE##/'),
330 array($op['stereotype'],$op['package'],$op['id'],$op['type'],$op['abstract'],trim($op['documentation']),$op['name'],
331 $op['static'],$op['scope'],$op['value']),
333 //Prepare attributes listitem line
334 $tmp2 = $umllistitem;
335 $LISTITEM.= preg_replace (array('/##TYPE##/','/##LABEL##/','/##ID##/'),array(814, $op['name'], $op['id']),$tmp2)."\n";
336 $LISTITEM.=$umllistitem_c."\n";
338 fwrite($m,$umlclass_c);
339 $LISTITEM.=$umllistitem_c."\n";
341 fwrite($m, $xmi_half. $LISTITEM."\n".$xmi_end);
345 //parsePARENTHESIS {{{
346 //This function receives the content between the parenthesis ( with the ( and the ) )
347 //It's a recursive function
348 //Returns an array of arrays
349 function parseParenthesis($value) {
354 $value = substr(substr(trim($value), 1), 0, strrpos(substr(trim($value), 1),')')); //Removes the ( and the )
357 //I look for the following separation ( , or = ) {{{
358 //If its an = then I check if the next character is an >
359 if (!strpos($value, ',') && !strpos($value, '=')) {
362 elseif (!strpos($value, ',') && strpos($value, '=')) {
363 if ($value{strpos($value, '=') + 1} == '>') {
370 elseif (strpos($value, ',') && !strpos($value, '=')) {
373 elseif (strpos($value, ',') && strpos($value, '=') && strpos($value, ',') > strpos($value, '=')) {
374 if ($value{strpos($value, '=') + 1} == '>') {
381 elseif (strpos($value, ',') && strpos($value, '=') && strpos($value, ',') < strpos($value, '=')) {
386 //Get's the option name {{{
387 $result[$pos]['name'] = (strpos($value, $char)) ? substr($value, 0, strpos($value, $char)) : $value;
388 $pos_del = strpos($value, $char);
391 //If $char is an = or an =>, gets the option value {{{
393 $op_value = (strpos($value, $char)) ? trim(substr($value, strpos($value, $char) + 1)) : false;
395 elseif ($char == '=>') {
396 $op_value = (strpos($value, $char)) ? trim(substr($value, strpos($value, $char) + 2)) : false;
400 //Parse the rest of the line {{{
402 if ($op_value{0} == "'" || $op_value{0} == '"') {
403 $pos_del = parseString($op_value);
405 $result[$pos]['value'] = "''";
408 $op_value = substr($op_value, 1);
409 $result[$pos]['value'] = substr($op_value, 0, $pos_del);
412 elseif (trim(strtolower(substr($op_value, 0 ,5))) == 'array') { //Recursive part {{{
413 $op_value = trim(substr($op_value, 5));
414 $op_value = trim(substr($op_value, 1)); //Removes the (
416 if ($op_value{0} == ')') {
417 $result[$pos]['value'] = 'array()';
420 //I look for the colsing ) {{{
425 if (($temp{$subpos} == '"' || $temp{$subpos} == "'") && $temp{$subpos - 1} != '\\') {
426 $pos_del = parseString(substr($temp,$subpos)) + $subpos;
427 $subpos = $pos_del + 2;
429 if (trim($temp{$subpos}) == ')') {
434 if ($subpos > strlen($temp)) {
441 $par = parseParenthesis('('.substr($op_value, 0 , $subpos).')');
442 $result[$pos]['value'] = 'array(';
443 foreach ($par as $p) {
444 $result[$pos]['value'] .= $p['name'];
446 $result[$pos]['value'] .= '=>\''.$p['value'].'\',';
449 $result[$pos]['value'] .= ',';
452 $result[$pos]['value'] = rtrim($result[$pos]['value'],',');
453 $result[$pos]['value'] .= ')';
458 //Look for the next parameter. If its the last one
459 //I assign it as it came.
460 if ($pos_del = strpos($op_value, ',')) {
461 $result[$pos]['value'] = ($pos_del) ? trim(substr($op_value, 0, $pos_del)): $op_value;
468 //Removes from $value the part that's alredy parsed {{{
470 $value = trim(substr(trim($value), $pos_del + 2));
483 //Funtion that parse the content between "" or ''
484 //Returns the position of the final ' or "
485 function parseString($value) {
489 switch ($value{0}) { //{{{
497 $value = substr($value, 1); //Removes the ' or the " from the beginning of the string
498 if ($value{0} == $char) {
502 while ($cont) { //{{{
504 if ($value{$ii} == $char) {
505 if ($value{$ii - 1} != '\\') {