3 /* vim: set binary expandtab tabstop=4 shiftwidth=4:
4 -------------------------------------------------------------------------------
5 Creado: jue jul 31 14:01:57 ART 2003
6 Autor: Martin Marrese <mmarre@mecon.gov.ar>
7 -------------------------------------------------------------------------------
9 -----------------------------------------------------------------------------*/
10 //////////////////////
12 //////////////////////
14 <?xml version="1.0" encoding="UTF-8"?>
15 <XMI xmlns:UML="org.omg/standards/UML" verified="false" timestamp="" xmi.version="1.2" >
22 <listitem open="1" type="800" id="-1" label="Views" >
23 <listitem open="1" type="801" id="-1" label="Logical View" >
27 <listitem open="1" type="802" id="-1" label="Use Case View" />
35 $umlclass = '<UML:Class stereotype="##STEREOTYPE##" package="##PACKAGE##" xmi.id="##ID##" abstract="##ABSTRACT##" documentation="##DOCUMENTATION##" name="##NAME##" static="##STATIC##" scope="##SCOPE##" >';
36 $umlclass_c = '</UML:Class>';
38 $umloperation = '<UML:Operation stereotype="##STEREOTYPE##" package="##PACKAGE##" xmi.id="##ID##" type="##TYPE##" abstract="##ABSTRACT##" documentation="##DOCUMENTATION##" name="##NAME##" static="##STATIC##" scope="##SCOPE##">';
39 $umloperation_c = '</UML:Operation>';
41 $umlparameter = '<UML:Parameter stereotype="##STEREOTYPE##" package="##PACKAGE##" xmi.id="##ID##" value="##VALUE##" type="##TYPE##" abstract="##ABSTRACT##" documentation="##DOCUMENTATION##" name="##NAME##" static="##STATIC##" scope="##SCOPE##" />';
43 $umlattribute = '<UML:Attribute stereotype="##STEREOTYPE##" package="##PACKAGE##" xmi.id="##ID##" value="##VALUE##" type="##TYPE##" abstract="##ABSTRACT##" documentation="##DOCUMENTATION##" name="##NAME##" static="##STATIC##" scope="##SCOPE##" />';
45 $umllistitem = '<listitem open="0" type="##TYPE##" id="##ID##" label="##LABEL##" >';
46 $umllistitem_c = '</listitem>';
48 //////////////////////
55 for ($j = 1; $j < count($argv); $j++) {
57 // Si es un directorio, agrego cada archivo legible .php al argv.
60 while (($f = readdir($dh)) !== false) {
61 if (is_readable("$file/$f") and substr($f, -4) == '.php') {
67 // Si no, si se puede leer el archivo y es .php, lo procesa.
68 } elseif (is_readable($file) and substr($file, -4) == '.php') {
71 $DOCUMENTANDO = false;
74 foreach ($cont as $linea) {
75 $linea = trim ($linea);
76 $tmp = preg_split ('/[^\w_\/\*\@\$\']+/', $linea);
77 //Agrego la documentacion
78 if ($tmp['0'] == '/**') { //Comienza la documentacion
81 if ($tmp['0'] == '*/') { //Termina la documentacion
82 $DOCUMENTANDO = false;
86 if ($tmp['0'] = '*') {
92 case 'private' : $opciones['access'] = 201;
94 case 'protected': $opciones['access'] = 202;
96 default : $opciones['access'] = 200;
99 case '@package' : $opciones['package'] = $tmp['1'];
101 case '@abstract': $opciones['abstract'] = 1;
103 case '@static' : $opciones['static'] = 1;
105 case '@var' : $opciones['type'] = $tmp['1'];
107 case '@return' : $opciones['type'] = $tmp['1'];
109 case '@param' : $opciones['param'][$cont_param]['type'] = $tmp['1'];
110 $opciones['param'][$cont_param]['documentacion'] = implode (' ', array_slice($tmp,3));
114 if (array_key_exists('0',$tmp)) {
115 @$opciones['documentacion'].= implode (' ',$tmp)."\n";
121 if (!$DOCUMENTANDO && $tmp['0'] == 'class') {
125 $ARRAY[$ID]['id'] = $ID;
126 $ARRAY[$ID]['name'] = $tmp['1'];
127 $ARRAY[$ID]['stereotype'] = (@$opciones['stereotype']) ? $opciones['stereotype'] : '';
128 $ARRAY[$ID]['package'] = (@$opciones['package']) ? $opciones['package'] : '';
129 $ARRAY[$ID]['abstract'] = (@$opciones['abstract']) ? $opciones['abstract'] : 0;
130 $ARRAY[$ID]['documentation'] = (@$opciones['documentacion']) ? $opciones['documentacion'] : '';
131 $ARRAY[$ID]['static'] = (@$opciones['static']) ? $opciones['static'] : 0;
132 $ARRAY[$ID]['scope'] = (@$opciones['access']) ? $opciones['access'] : 200;
133 $ARRAY[$ID]['operations'] = array();
134 $ARRAY[$ID]['attributes'] = array();
138 if (!$DOCUMENTANDO && $tmp['0'] == 'function') {
140 $ARRAY[$IDCLASE]['operations'][$ID]['id'] = $ID;
141 $ARRAY[$IDCLASE]['operations'][$ID]['name'] = $tmp['1'];
142 $ARRAY[$IDCLASE]['operations'][$ID]['stereotype'] = (@$opciones['stereotype']) ? $opciones['stereotype'] : '';
143 $ARRAY[$IDCLASE]['operations'][$ID]['package'] = (@$opciones['package']) ? $opciones['package'] : '';
144 $ARRAY[$IDCLASE]['operations'][$ID]['abstract'] = (@$opciones['abstract']) ? $opciones['abstract'] : 0;
145 $ARRAY[$IDCLASE]['operations'][$ID]['documentation'] = (@$opciones['documentacion']) ? $opciones['documentacion'] : '';
146 $ARRAY[$IDCLASE]['operations'][$ID]['static'] = (@$opciones['static']) ? $opciones['static'] : 0;
147 $ARRAY[$IDCLASE]['operations'][$ID]['scope'] = (@$opciones['access']) ? $opciones['access'] : 200;
148 $ARRAY[$IDCLASE]['operations'][$ID]['type'] = (@$opciones['type']) ? $opciones['type'] : '';
149 $ARRAY[$IDCLASE]['operations'][$ID]['param'] = array();
152 array_shift($tmp); //SACO EL FUNCTION
153 array_shift($tmp); //SACO EL NOMBRE DE LA FUNCION
154 for ($i = 0; $i <= count($tmp); $i++) {
155 if ($tmp[$i]{0} == '$') { //AL FINAL DEJE EL $ PARA DIFERENCIAR LOS PARAMETROS DE LOS VALORES INICIALES QUE TOMAN
156 $tmp[$i] = substr($tmp[$i], 1); //SACO EL $
158 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['id'] = $i;
159 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['name'] = $tmp[$i];
160 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['stereotype'] = (@$opciones['param'][$i]['stereotype']) ? $opciones['param'][$i]['stereotype'] : '';
161 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['package'] = (@$opciones['param'][$i]['package']) ? $opciones['param'][$i]['package'] : '';
162 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['abstract'] = (@$opciones['param'][$i]['abstract']) ? $opciones['param'][$i]['abstract'] : 0;
163 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['documentation'] = (@$opciones['param'][$i]['documentacion']) ? $opciones['param'][$i]['documentacion'] : '';
164 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['static'] = (@$opciones['param'][$i]['static']) ? $opciones['param'][$i]['static'] : 0;
165 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['scope'] = (@$opciones['param'][$i]['access']) ? $opciones['param'][$i]['access'] : '';
166 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['type'] = (@$opciones['param'][$i]['type']) ? $opciones['param'][$i]['type'] : '';
168 elseif ($tmp[$i] != '//' && $tmp[$i] != 'X2C' && $tmp[$i] != '') {
169 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$OPANT]['value'] .= $tmp[$i];
176 if (!$DOCUMENTANDO && $tmp['0'] == 'var') {
178 $tmp['1'] = substr($tmp['1'], 1); //SACO EL $
179 if ($tmp['1']{0} == '_') {
180 $tmp['1'] = substr($tmp['1'],1); //SACO EL _
181 if (!(@$opciones['access'])) {
182 $opciones['access'] = 201;
185 //Agrego si tiene valor inicial
186 if (array_key_exists('2',$tmp)) {
187 $opciones['value'] = $tmp['2'];
190 $ARRAY[$IDCLASE]['attributes'][$ID]['id'] = $ID;
191 $ARRAY[$IDCLASE]['attributes'][$ID]['name'] = $tmp['1'];
192 $ARRAY[$IDCLASE]['attributes'][$ID]['stereotype'] = (@$opciones['stereotype']) ? $opciones['stereotype'] : '';
193 $ARRAY[$IDCLASE]['attributes'][$ID]['package'] = (@$opciones['package']) ? $opciones['package'] : '';
194 $ARRAY[$IDCLASE]['attributes'][$ID]['abstract'] = (@$opciones['abstract']) ? $opciones['abstract'] : 0;
195 $ARRAY[$IDCLASE]['attributes'][$ID]['documentation'] = (@$opciones['documentacion']) ? $opciones['documentacion'] : '';
196 $ARRAY[$IDCLASE]['attributes'][$ID]['static'] = (@$opciones['static']) ? $opciones['static'] : 0;
197 $ARRAY[$IDCLASE]['attributes'][$ID]['scope'] = (@$opciones['access']) ? $opciones['access'] : 200;
198 $ARRAY[$IDCLASE]['attributes'][$ID]['type'] = (@$opciones['type']) ? $opciones['type'] : '';
199 $ARRAY[$IDCLASE]['attributes'][$ID]['value'] = (@$opciones['value']) ? $opciones['value'] : '';
200 $opciones = array(operations);
206 $m = fopen ('./umlOut.xmi', 'w');
207 fwrite($m, $comienzo);
210 foreach ($ARRAY as $ar) {
211 //PREPARO LA CLASE {{{
213 fwrite($m, preg_replace (array ('/##STEREOTYPE##/','/##PACKAGE##/','/##ID##/','/##ABSTRACT##/','/##DOCUMENTATION##/','/##NAME##/',
214 '/##STATIC##/','/##SCOPE##/'),
215 array ($ar['stereotype'],$ar['package'],$ar['id'],$ar['abstract'],$ar['documentation'],$ar['name'],
216 $ar['static'],$ar['scope']),
218 //PREPARO LOS LISTITEM {{{
219 $tmp2 = $umllistitem;
220 $LISTITEM.= preg_replace (array('/##TYPE##/','/##LABEL##/','/##ID##/'),array(813, $ar['name'], $ar['id']),$tmp2)."\n";
223 foreach ($ar['operations'] as $op) {
224 $tmp2 = $umloperation;
225 fwrite($m, preg_replace (array('/##STEREOTYPE##/','/##PACKAGE##/','/##ID##/','/##TYPE##/','/##ABSTRACT##/','/##DOCUMENTATION##/',
226 '/##NAME##/','/##STATIC##/','/##SCOPE##/'),
227 array($op['stereotype'],$op['package'],$op['id'],$op['type'],$op['abstract'],$op['documentation'],
228 $op['name'],$op['static'],$op['scope']) ,
230 //PARAMETROS NO TIENE LISTITEM
231 foreach ($op['param'] as $pa) {
232 $tmp2 = $umlparameter;
233 fwrite ($m, preg_replace(array('/##STEREOTYPE##/','/##PACKAGE##/','/##ID##/','/##TYPE##/','/##ABSTRACT##/','/##DOCUMENTATION##/',
234 '/##NAME##/','/##STATIC##/','/##SCOPE##/','/##VALUE##/'),
235 array($pa['stereotype'],$pa['package'],$pa['id'],$pa['type'],$pa['abstract'],$pa['documentation'],
236 $pa['name'],$pa['static'],$pa['scope'],$pa['value']),
239 fwrite($m,$umloperation_c."\n");
240 //PREPARO LOS LISTITEM {{{
241 $tmp2 = $umllistitem;
242 $LISTITEM.= preg_replace (array('/##TYPE##/','/##LABEL##/','/##ID##/'),array(815, $op['name'], $op['id']),$tmp2)."\n";
243 $LISTITEM.=$umllistitem_c."\n";
246 foreach ($ar['attributes'] as $op) {
247 $tmp2 = $umlattribute;
248 fwrite($m, preg_replace(array('/##STEREOTYPE##/','/##PACKAGE##/','/##ID##/','/##TYPE##/','/##ABSTRACT##/','/##DOCUMENTATION##/',
249 '/##NAME##/','/##STATIC##/','/##SCOPE##/','/##VALUE##/'),
250 array($op['stereotype'],$op['package'],$op['id'],$op['type'],$op['abstract'],$op['documentation'],$op['name'],
251 $op['static'],$op['scope'],$op['value']),
253 //PREPARO LOS LISTITEM {{{
254 $tmp2 = $umllistitem;
255 $LISTITEM.= preg_replace (array('/##TYPE##/','/##LABEL##/','/##ID##/'),array(814, $op['name'], $op['id']),$tmp2)."\n";
256 $LISTITEM.=$umllistitem_c."\n";
258 fwrite($m,$umlclass_c);
259 $LISTITEM.=$umllistitem_c."\n";
262 fwrite($m, $medio. $LISTITEM."\n".$fin);