3 /* vim: set binary expandtab tabstop=4 shiftwidth=4 foldmethod=marker:
4 -------------------------------------------------------------------------------
5 Creado: jue jul 31 14:01:57 ART 2003
6 Autor: Martin Marrese <mmarre@mecon.gov.ar>
7 -------------------------------------------------------------------------------
9 -----------------------------------------------------------------------------*/
11 //Recibe como parametros el directorio o una lista de archivos a diagramar
15 <?xml version="1.0" encoding="UTF-8"?>
16 <XMI xmlns:UML="org.omg/standards/UML" verified="false" timestamp="" xmi.version="1.2" >
23 <listitem open="1" type="800" id="-1" label="Views" >
24 <listitem open="1" type="801" id="-1" label="Logical View" >
28 <listitem open="1" type="802" id="-1" label="Use Case View" />
35 //LINEAS TEMPLATES XMI {{{
36 $umlclass = '<UML:Class stereotype="##STEREOTYPE##" package="##PACKAGE##" xmi.id="##ID##" abstract="##ABSTRACT##" documentation="##DOCUMENTATION##" name="##NAME##" static="##STATIC##" scope="##SCOPE##" >';
37 $umlclass_c = '</UML:Class>';
39 $umloperation = '<UML:Operation stereotype="##STEREOTYPE##" package="##PACKAGE##" xmi.id="##ID##" type="##TYPE##" abstract="##ABSTRACT##" documentation="##DOCUMENTATION##" name="##NAME##" static="##STATIC##" scope="##SCOPE##">';
40 $umloperation_c = '</UML:Operation>';
42 $umlparameter = '<UML:Parameter stereotype="##STEREOTYPE##" package="##PACKAGE##" xmi.id="##ID##" value="##VALUE##" type="##TYPE##" abstract="##ABSTRACT##" documentation="##DOCUMENTATION##" name="##NAME##" static="##STATIC##" scope="##SCOPE##" />';
44 $umlattribute = '<UML:Attribute stereotype="##STEREOTYPE##" package="##PACKAGE##" xmi.id="##ID##" value="##VALUE##" type="##TYPE##" abstract="##ABSTRACT##" documentation="##DOCUMENTATION##" name="##NAME##" static="##STATIC##" scope="##SCOPE##" />';
46 $umllistitem = '<listitem open="0" type="##TYPE##" id="##ID##" label="##LABEL##" >';
47 $umllistitem_c = '</listitem>';
49 //VARIABLES GLOBALES {{{
56 for ($j = 1; $j < count($argv); $j++) {
58 //ARMO LA LISTA DE ARCHIVOS {{{
59 // Si es un directorio, agrego cada archivo legible .php al argv.
62 while (($f = readdir($dh)) !== false) {
63 if (is_readable("$file/$f") and substr($f, -4) == '.php') {
72 elseif (is_readable($file) and substr($file, -4) == '.php') {
74 $DOCUMENTANDO = false;
77 foreach ($cont as $linea) {
78 $linea = trim ($linea);
79 $tmp = preg_split ('/[^\w_\/\*\@\$\&\.\']+/', $linea);
81 if ($tmp['0'] == '/**') { //Comienza la documentacion
84 if ($tmp['0'] == '*/') { //Termina la documentacion
85 $DOCUMENTANDO = false;
88 $tmp2 = ltrim ($linea,'* /**'); //Elimino el * o /** del comienzo de la linea
89 $accion = substr($tmp2, 0, strpos($tmp2,' ')); //Obtengo la accion
90 $value = trim(strstr($tmp2, ' ')); //Solo me importa lo que esta detras del @
93 case '@access' : switch ($value) {
94 case 'private' : $opciones['access'] = 201;
96 case 'protected': $opciones['access'] = 202;
98 default : $opciones['access'] = 200;
102 case '@package' : $opciones['package'] = $value;
105 case '@abstract': $opciones['abstract'] = 1;
108 case '@static' : $opciones['static'] = 1;
111 case '@var' : $opciones['type'] = substr($value, 0, strpos($value,' '));
114 case '@return' : $opciones['type'] = $value;
117 case '@param' : $opciones['param'][$cont_param]['type'] = substr($value, 0, strpos($value,' '));
118 $opciones['param'][$cont_param]['documentacion'] = trim(strstr(trim(strstr($value, ' ')), ' '));
124 $opciones['param'][$cont_param]['documentacion'].= $tmp2;
127 @$opciones['documentacion'].= $tmp2;
133 if (!$DOCUMENTANDO && $tmp['0'] == 'class') {
137 $ARRAY[$ID]['id'] = $ID;
138 $ARRAY[$ID]['name'] = $tmp['1'];
139 $ARRAY[$ID]['stereotype'] = (@$opciones['stereotype']) ? $opciones['stereotype'] : '';
140 $ARRAY[$ID]['package'] = (@$opciones['package']) ? $opciones['package'] : '';
141 $ARRAY[$ID]['abstract'] = (@$opciones['abstract']) ? $opciones['abstract'] : 0;
142 $ARRAY[$ID]['documentation'] = (@$opciones['documentacion']) ? $opciones['documentacion'] : '';
143 $ARRAY[$ID]['static'] = (@$opciones['static']) ? $opciones['static'] : 0;
144 $ARRAY[$ID]['scope'] = (@$opciones['access']) ? $opciones['access'] : 200;
145 $ARRAY[$ID]['operations'] = array();
146 $ARRAY[$ID]['attributes'] = array();
151 if (!$DOCUMENTANDO && $tmp['0'] == 'function') {
154 if ($tmp['1']{0} == '_') {
155 $tmp['1'] = substr($tmp['1'], 1); //SACO EL _
158 $ARRAY[$IDCLASE]['operations'][$ID]['id'] = $ID;
159 $ARRAY[$IDCLASE]['operations'][$ID]['name'] = $tmp['1'];
160 $ARRAY[$IDCLASE]['operations'][$ID]['stereotype'] = (@$opciones['stereotype']) ? $opciones['stereotype'] : '';
161 $ARRAY[$IDCLASE]['operations'][$ID]['package'] = (@$opciones['package']) ? $opciones['package'] : '';
162 $ARRAY[$IDCLASE]['operations'][$ID]['abstract'] = (@$opciones['abstract']) ? $opciones['abstract'] : 0;
163 $ARRAY[$IDCLASE]['operations'][$ID]['documentation'] = (@$opciones['documentacion']) ? $opciones['documentacion'] : '';
164 $ARRAY[$IDCLASE]['operations'][$ID]['static'] = (@$opciones['static']) ? $opciones['static'] : 0;
165 $ARRAY[$IDCLASE]['operations'][$ID]['scope'] = (@$opciones['access']) ? $opciones['access'] : 200;
166 $ARRAY[$IDCLASE]['operations'][$ID]['type'] = (@$opciones['type']) ? $opciones['type'] : '';
167 $ARRAY[$IDCLASE]['operations'][$ID]['param'] = array();
170 array_shift($tmp); //SACO EL FUNCTION
171 array_shift($tmp); //SACO EL NOMBRE DE LA FUNCION
172 for ($i = 0; $i <= count($tmp); $i++) {
173 if ($tmp[$i]{0} == '$'|| $tmp[$i]{0} == '&') { //Veo si empiezo con $ o &
174 switch ($tmp[$i]{0}) {
175 case '$': $tmp[$i] = substr($tmp[$i], 1); //SACO EL $
177 case '&': $tmp[$i] = substr($tmp[$i], 2); //SACO EL & Y EL $
178 $opciones['param'][$i]['type'] =
179 (@$opciones['param'][$i]['type']) ? '&'.$opciones['param'][$i]['type'] : '';
183 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['id'] = $i;
184 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['name'] = $tmp[$i];
185 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['stereotype'] =
186 (@$opciones['param'][$i]['stereotype']) ? $opciones['param'][$i]['stereotype'] : '';
187 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['package'] =
188 (@$opciones['param'][$i]['package']) ? $opciones['param'][$i]['package'] : '';
189 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['abstract'] =
190 (@$opciones['param'][$i]['abstract']) ? $opciones['param'][$i]['abstract'] : 0;
191 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['documentation'] =
192 (@$opciones['param'][$i]['documentacion']) ? $opciones['param'][$i]['documentacion'] : '';
193 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['static'] =
194 (@$opciones['param'][$i]['static']) ? $opciones['param'][$i]['static'] : 0;
195 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['scope'] =
196 (@$opciones['param'][$i]['access']) ? $opciones['param'][$i]['access'] : '';
197 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['type'] =
198 (@$opciones['param'][$i]['type']) ? $opciones['param'][$i]['type'] : '';
200 elseif ($tmp[$i] != '//' && $tmp[$i] != 'X2C' && $tmp[$i] != '') {
201 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$OPANT]['value'] .= $tmp[$i];
210 if (!$DOCUMENTANDO && $tmp['0'] == 'var') {
212 $tmp['1'] = substr($tmp['1'], 1); //SACO EL $
213 if ($tmp['1']{0} == '_') {
214 $tmp['1'] = substr($tmp['1'],1); //SACO EL _
215 if (!(@$opciones['access'])) {
216 $opciones['access'] = 201;
219 //Agrego si tiene valor inicial
220 if (array_key_exists('2',$tmp)) {
221 $opciones['value'] = $tmp['2'];
224 $ARRAY[$IDCLASE]['attributes'][$ID]['id'] = $ID;
225 $ARRAY[$IDCLASE]['attributes'][$ID]['name'] = $tmp['1'];
226 $ARRAY[$IDCLASE]['attributes'][$ID]['stereotype'] = (@$opciones['stereotype']) ? $opciones['stereotype'] : '';
227 $ARRAY[$IDCLASE]['attributes'][$ID]['package'] = (@$opciones['package']) ? $opciones['package'] : '';
228 $ARRAY[$IDCLASE]['attributes'][$ID]['abstract'] = (@$opciones['abstract']) ? $opciones['abstract'] : 0;
229 $ARRAY[$IDCLASE]['attributes'][$ID]['documentation'] = (@$opciones['documentacion']) ? $opciones['documentacion'] : '';
230 $ARRAY[$IDCLASE]['attributes'][$ID]['static'] = (@$opciones['static']) ? $opciones['static'] : 0;
231 $ARRAY[$IDCLASE]['attributes'][$ID]['scope'] = (@$opciones['access']) ? $opciones['access'] : 200;
232 $ARRAY[$IDCLASE]['attributes'][$ID]['type'] = (@$opciones['type']) ? $opciones['type'] : '';
233 $ARRAY[$IDCLASE]['attributes'][$ID]['value'] = (@$opciones['value']) ? $opciones['value'] : '';
234 $opciones = array(operations);
244 //GUARDO EN EL ARCHIVO {{{
245 $m =fopen ('./umlOut.xmi', 'w');
246 fwrite($m, $comienzo);
249 foreach ($ARRAY as $ar) {
252 fwrite($m, preg_replace (array ('/##STEREOTYPE##/','/##PACKAGE##/','/##ID##/','/##ABSTRACT##/','/##DOCUMENTATION##/','/##NAME##/',
253 '/##STATIC##/','/##SCOPE##/'),
254 array ($ar['stereotype'],$ar['package'],$ar['id'],$ar['abstract'],$ar['documentation'],$ar['name'],
255 $ar['static'],$ar['scope']),
257 //PREPARO LOS LISTITEM
258 $tmp2 = $umllistitem;
259 $LISTITEM.= preg_replace (array('/##TYPE##/','/##LABEL##/','/##ID##/'),array(813, $ar['name'], $ar['id']),$tmp2)."\n";
262 foreach ($ar['operations'] as $op) {
263 $tmp2 = $umloperation;
264 fwrite($m, preg_replace (array('/##STEREOTYPE##/','/##PACKAGE##/','/##ID##/','/##TYPE##/','/##ABSTRACT##/','/##DOCUMENTATION##/',
265 '/##NAME##/','/##STATIC##/','/##SCOPE##/'),
266 array($op['stereotype'],$op['package'],$op['id'],$op['type'],$op['abstract'],$op['documentation'],
267 $op['name'],$op['static'],$op['scope']) ,
269 //PARAMETROS NO TIENE LISTITEM
270 foreach ($op['param'] as $pa) {
271 $tmp2 = $umlparameter;
272 fwrite ($m, preg_replace(array('/##STEREOTYPE##/','/##PACKAGE##/','/##ID##/','/##TYPE##/','/##ABSTRACT##/','/##DOCUMENTATION##/',
273 '/##NAME##/','/##STATIC##/','/##SCOPE##/','/##VALUE##/'),
274 array($pa['stereotype'],$pa['package'],$pa['id'],$pa['type'],$pa['abstract'],$pa['documentation'],
275 $pa['name'],$pa['static'],$pa['scope'],$pa['value']),
278 fwrite($m,$umloperation_c."\n");
279 //PREPARO LOS LISTITEM
280 $tmp2 = $umllistitem;
281 $LISTITEM.= preg_replace (array('/##TYPE##/','/##LABEL##/','/##ID##/'),array(815, $op['name'], $op['id']),$tmp2)."\n";
282 $LISTITEM.=$umllistitem_c."\n";
285 foreach ($ar['attributes'] as $op) {
286 $tmp2 = $umlattribute;
287 fwrite($m, preg_replace(array('/##STEREOTYPE##/','/##PACKAGE##/','/##ID##/','/##TYPE##/','/##ABSTRACT##/','/##DOCUMENTATION##/',
288 '/##NAME##/','/##STATIC##/','/##SCOPE##/','/##VALUE##/'),
289 array($op['stereotype'],$op['package'],$op['id'],$op['type'],$op['abstract'],$op['documentation'],$op['name'],
290 $op['static'],$op['scope'],$op['value']),
292 //PREPARO LOS LISTITEM
293 $tmp2 = $umllistitem;
294 $LISTITEM.= preg_replace (array('/##TYPE##/','/##LABEL##/','/##ID##/'),array(814, $op['name'], $op['id']),$tmp2)."\n";
295 $LISTITEM.=$umllistitem_c."\n";
297 fwrite($m,$umlclass_c);
298 $LISTITEM.=$umllistitem_c."\n";
300 fwrite($m, $medio. $LISTITEM."\n".$fin);