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 -----------------------------------------------------------------------------*/
11 //Recibe como parametros el directorio o una lista de archivos a diagramar
13 //////////////////////
15 //////////////////////
17 <?xml version="1.0" encoding="UTF-8"?>
18 <XMI xmlns:UML="org.omg/standards/UML" verified="false" timestamp="" xmi.version="1.2" >
25 <listitem open="1" type="800" id="-1" label="Views" >
26 <listitem open="1" type="801" id="-1" label="Logical View" >
30 <listitem open="1" type="802" id="-1" label="Use Case View" />
38 $umlclass = '<UML:Class stereotype="##STEREOTYPE##" package="##PACKAGE##" xmi.id="##ID##" abstract="##ABSTRACT##" documentation="##DOCUMENTATION##" name="##NAME##" static="##STATIC##" scope="##SCOPE##" >';
39 $umlclass_c = '</UML:Class>';
41 $umloperation = '<UML:Operation stereotype="##STEREOTYPE##" package="##PACKAGE##" xmi.id="##ID##" type="##TYPE##" abstract="##ABSTRACT##" documentation="##DOCUMENTATION##" name="##NAME##" static="##STATIC##" scope="##SCOPE##">';
42 $umloperation_c = '</UML:Operation>';
44 $umlparameter = '<UML:Parameter stereotype="##STEREOTYPE##" package="##PACKAGE##" xmi.id="##ID##" value="##VALUE##" type="##TYPE##" abstract="##ABSTRACT##" documentation="##DOCUMENTATION##" name="##NAME##" static="##STATIC##" scope="##SCOPE##" />';
46 $umlattribute = '<UML:Attribute stereotype="##STEREOTYPE##" package="##PACKAGE##" xmi.id="##ID##" value="##VALUE##" type="##TYPE##" abstract="##ABSTRACT##" documentation="##DOCUMENTATION##" name="##NAME##" static="##STATIC##" scope="##SCOPE##" />';
48 $umllistitem = '<listitem open="0" type="##TYPE##" id="##ID##" label="##LABEL##" >';
49 $umllistitem_c = '</listitem>';
51 //////////////////////
58 for ($j = 1; $j < count($argv); $j++) {
60 // Si es un directorio, agrego cada archivo legible .php al argv.
63 while (($f = readdir($dh)) !== false) {
64 if (is_readable("$file/$f") and substr($f, -4) == '.php') {
70 // Si no, si se puede leer el archivo y es .php, lo procesa.
71 } 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);
80 //Agrego la documentacion
81 if ($tmp['0'] == '/**') { //Comienza la documentacion
84 if ($tmp['0'] == '*/') { //Termina la documentacion
85 $DOCUMENTANDO = false;
89 if ($tmp['0'] = '*') {
95 case 'private' : $opciones['access'] = 201;
97 case 'protected': $opciones['access'] = 202;
99 default : $opciones['access'] = 200;
102 case '@package' : $opciones['package'] = $tmp['1'];
104 case '@abstract': $opciones['abstract'] = 1;
106 case '@static' : $opciones['static'] = 1;
108 case '@var' : $opciones['type'] = $tmp['1'];
110 case '@return' : $opciones['type'] = $tmp['1'];
112 case '@param' : $opciones['param'][$cont_param]['type'] = $tmp['1'];
113 $opciones['param'][$cont_param]['documentacion'] = implode (' ', array_slice($tmp,3));
117 if (array_key_exists('0',$tmp)) {
118 @$opciones['documentacion'].= implode (' ',$tmp)."\n";
124 if (!$DOCUMENTANDO && $tmp['0'] == 'class') {
128 $ARRAY[$ID]['id'] = $ID;
129 $ARRAY[$ID]['name'] = $tmp['1'];
130 $ARRAY[$ID]['stereotype'] = (@$opciones['stereotype']) ? $opciones['stereotype'] : '';
131 $ARRAY[$ID]['package'] = (@$opciones['package']) ? $opciones['package'] : '';
132 $ARRAY[$ID]['abstract'] = (@$opciones['abstract']) ? $opciones['abstract'] : 0;
133 $ARRAY[$ID]['documentation'] = (@$opciones['documentacion']) ? $opciones['documentacion'] : '';
134 $ARRAY[$ID]['static'] = (@$opciones['static']) ? $opciones['static'] : 0;
135 $ARRAY[$ID]['scope'] = (@$opciones['access']) ? $opciones['access'] : 200;
136 $ARRAY[$ID]['operations'] = array();
137 $ARRAY[$ID]['attributes'] = array();
141 if (!$DOCUMENTANDO && $tmp['0'] == 'function') {
143 $ARRAY[$IDCLASE]['operations'][$ID]['id'] = $ID;
144 $ARRAY[$IDCLASE]['operations'][$ID]['name'] = $tmp['1'];
145 $ARRAY[$IDCLASE]['operations'][$ID]['stereotype'] = (@$opciones['stereotype']) ? $opciones['stereotype'] : '';
146 $ARRAY[$IDCLASE]['operations'][$ID]['package'] = (@$opciones['package']) ? $opciones['package'] : '';
147 $ARRAY[$IDCLASE]['operations'][$ID]['abstract'] = (@$opciones['abstract']) ? $opciones['abstract'] : 0;
148 $ARRAY[$IDCLASE]['operations'][$ID]['documentation'] = (@$opciones['documentacion']) ? $opciones['documentacion'] : '';
149 $ARRAY[$IDCLASE]['operations'][$ID]['static'] = (@$opciones['static']) ? $opciones['static'] : 0;
150 $ARRAY[$IDCLASE]['operations'][$ID]['scope'] = (@$opciones['access']) ? $opciones['access'] : 200;
151 $ARRAY[$IDCLASE]['operations'][$ID]['type'] = (@$opciones['type']) ? $opciones['type'] : '';
152 $ARRAY[$IDCLASE]['operations'][$ID]['param'] = array();
155 array_shift($tmp); //SACO EL FUNCTION
156 array_shift($tmp); //SACO EL NOMBRE DE LA FUNCION
157 for ($i = 0; $i <= count($tmp); $i++) {
158 if ($tmp[$i]{0} == '$') { //AL FINAL DEJE EL $ PARA DIFERENCIAR LOS PARAMETROS DE LOS VALORES INICIALES QUE TOMAN
159 $tmp[$i] = substr($tmp[$i], 1); //SACO EL $
161 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['id'] = $i;
162 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['name'] = $tmp[$i];
163 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['stereotype'] = (@$opciones['param'][$i]['stereotype']) ? $opciones['param'][$i]['stereotype'] : '';
164 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['package'] = (@$opciones['param'][$i]['package']) ? $opciones['param'][$i]['package'] : '';
165 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['abstract'] = (@$opciones['param'][$i]['abstract']) ? $opciones['param'][$i]['abstract'] : 0;
166 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['documentation'] = (@$opciones['param'][$i]['documentacion']) ? $opciones['param'][$i]['documentacion'] : '';
167 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['static'] = (@$opciones['param'][$i]['static']) ? $opciones['param'][$i]['static'] : 0;
168 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['scope'] = (@$opciones['param'][$i]['access']) ? $opciones['param'][$i]['access'] : '';
169 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$i]['type'] = (@$opciones['param'][$i]['type']) ? $opciones['param'][$i]['type'] : '';
171 elseif ($tmp[$i] != '//' && $tmp[$i] != 'X2C' && $tmp[$i] != '') {
172 $ARRAY[$IDCLASE]['operations'][$ID]['param'][$OPANT]['value'] .= $tmp[$i];
179 if (!$DOCUMENTANDO && $tmp['0'] == 'var') {
181 $tmp['1'] = substr($tmp['1'], 1); //SACO EL $
182 if ($tmp['1']{0} == '_') {
183 $tmp['1'] = substr($tmp['1'],1); //SACO EL _
184 if (!(@$opciones['access'])) {
185 $opciones['access'] = 201;
188 //Agrego si tiene valor inicial
189 if (array_key_exists('2',$tmp)) {
190 $opciones['value'] = $tmp['2'];
193 $ARRAY[$IDCLASE]['attributes'][$ID]['id'] = $ID;
194 $ARRAY[$IDCLASE]['attributes'][$ID]['name'] = $tmp['1'];
195 $ARRAY[$IDCLASE]['attributes'][$ID]['stereotype'] = (@$opciones['stereotype']) ? $opciones['stereotype'] : '';
196 $ARRAY[$IDCLASE]['attributes'][$ID]['package'] = (@$opciones['package']) ? $opciones['package'] : '';
197 $ARRAY[$IDCLASE]['attributes'][$ID]['abstract'] = (@$opciones['abstract']) ? $opciones['abstract'] : 0;
198 $ARRAY[$IDCLASE]['attributes'][$ID]['documentation'] = (@$opciones['documentacion']) ? $opciones['documentacion'] : '';
199 $ARRAY[$IDCLASE]['attributes'][$ID]['static'] = (@$opciones['static']) ? $opciones['static'] : 0;
200 $ARRAY[$IDCLASE]['attributes'][$ID]['scope'] = (@$opciones['access']) ? $opciones['access'] : 200;
201 $ARRAY[$IDCLASE]['attributes'][$ID]['type'] = (@$opciones['type']) ? $opciones['type'] : '';
202 $ARRAY[$IDCLASE]['attributes'][$ID]['value'] = (@$opciones['value']) ? $opciones['value'] : '';
203 $opciones = array(operations);
209 $m = fopen ('./umlOut.xmi', 'w');
210 fwrite($m, $comienzo);
213 foreach ($ARRAY as $ar) {
214 //PREPARO LA CLASE {{{
216 fwrite($m, preg_replace (array ('/##STEREOTYPE##/','/##PACKAGE##/','/##ID##/','/##ABSTRACT##/','/##DOCUMENTATION##/','/##NAME##/',
217 '/##STATIC##/','/##SCOPE##/'),
218 array ($ar['stereotype'],$ar['package'],$ar['id'],$ar['abstract'],$ar['documentation'],$ar['name'],
219 $ar['static'],$ar['scope']),
221 //PREPARO LOS LISTITEM {{{
222 $tmp2 = $umllistitem;
223 $LISTITEM.= preg_replace (array('/##TYPE##/','/##LABEL##/','/##ID##/'),array(813, $ar['name'], $ar['id']),$tmp2)."\n";
226 foreach ($ar['operations'] as $op) {
227 $tmp2 = $umloperation;
228 fwrite($m, preg_replace (array('/##STEREOTYPE##/','/##PACKAGE##/','/##ID##/','/##TYPE##/','/##ABSTRACT##/','/##DOCUMENTATION##/',
229 '/##NAME##/','/##STATIC##/','/##SCOPE##/'),
230 array($op['stereotype'],$op['package'],$op['id'],$op['type'],$op['abstract'],$op['documentation'],
231 $op['name'],$op['static'],$op['scope']) ,
233 //PARAMETROS NO TIENE LISTITEM
234 foreach ($op['param'] as $pa) {
235 $tmp2 = $umlparameter;
236 fwrite ($m, preg_replace(array('/##STEREOTYPE##/','/##PACKAGE##/','/##ID##/','/##TYPE##/','/##ABSTRACT##/','/##DOCUMENTATION##/',
237 '/##NAME##/','/##STATIC##/','/##SCOPE##/','/##VALUE##/'),
238 array($pa['stereotype'],$pa['package'],$pa['id'],$pa['type'],$pa['abstract'],$pa['documentation'],
239 $pa['name'],$pa['static'],$pa['scope'],$pa['value']),
242 fwrite($m,$umloperation_c."\n");
243 //PREPARO LOS LISTITEM {{{
244 $tmp2 = $umllistitem;
245 $LISTITEM.= preg_replace (array('/##TYPE##/','/##LABEL##/','/##ID##/'),array(815, $op['name'], $op['id']),$tmp2)."\n";
246 $LISTITEM.=$umllistitem_c."\n";
249 foreach ($ar['attributes'] as $op) {
250 $tmp2 = $umlattribute;
251 fwrite($m, preg_replace(array('/##STEREOTYPE##/','/##PACKAGE##/','/##ID##/','/##TYPE##/','/##ABSTRACT##/','/##DOCUMENTATION##/',
252 '/##NAME##/','/##STATIC##/','/##SCOPE##/','/##VALUE##/'),
253 array($op['stereotype'],$op['package'],$op['id'],$op['type'],$op['abstract'],$op['documentation'],$op['name'],
254 $op['static'],$op['scope'],$op['value']),
256 //PREPARO LOS LISTITEM {{{
257 $tmp2 = $umllistitem;
258 $LISTITEM.= preg_replace (array('/##TYPE##/','/##LABEL##/','/##ID##/'),array(814, $op['name'], $op['id']),$tmp2)."\n";
259 $LISTITEM.=$umllistitem_c."\n";
261 fwrite($m,$umlclass_c);
262 $LISTITEM.=$umllistitem_c."\n";
265 fwrite($m, $medio. $LISTITEM."\n".$fin);