Php 5 + Uml

while playing around with the new object model of php 5 i discovered the
mighty reflection api. to explore its complete power i decided to write
a simple XMI generator (XMI is used by most UML tools for im/exporting diagrams).
i must admit i am impressed : i took me only 3-4 hours to get the
export stuff working. at the moment it only exports classes and interfaces but it is imho a very handy tool for getting an uml view on projects (see attachment). anyone interested in completing such a tool?

Sike

Sorry, but way above my current skills :frowning: Never really got a hold of UML.

The problem being for me at the moment is I see it as being wasteful of my time as I have no real need to use it just now :smiley:

But be interesting to see how things develop though :slight_smile:

Interesting, very interesting. I don’t know about completing it, but I would defenently like to see the code. This could be a good tool to get a quick overview of a class library. Played with a similar tool last year on a large app in C# and it was defenently a good help.

Brilliant! I was just viewing WACT’s documentation and even saw a request for someone to transform the current model into UML, and thought if it could be done automated.

Brilliant! Took the words …err… diagram right out of my mind. Are you going to try and start a project for an automated XMI/UML tool?

PS: Here is the specification for XMI for all those wondering. http://www.omg.org/technology/documents/formal/xmi.htm

Another interesting find: http://www.phpedit.net/products/xmi2php/

just cleaned some things up and zipped all files.
you will need php5 and mysql4 to run the scripts and
poseidonCE or any other xmi 2.0 capable editor to import
the xmi and create diagrams from it.

edit parse_source.php and generate_xmi.php for database settings.
parse_source : will persist all classes to mysql with REPLACE
generate_xmi : transforms persisted data into xmi v2.0 files : xmi.xmi and xmi.xml

Sike

ps. i am not shure if this really is xmi2 but poseidon claimed it (;

yep. but as far as i remember i had problems with its ugly output (:

Sike

Thank you sike.

I got the classes functioning and an XMI file was output but there was no class data for poseidon.

Can you rewrite the direcitons less compact, mabey I missed a step because my datbase is not populated with ANY data!?

Ok. Interesting project, look forward to seeing how it works.

PS: Take a look at the XMI and XML file I get as output

Played with it, had to fix the class names for the reflection classes though: ReflectionClass instead of Reflection_Class ( latest CVS ), other than that it worked like a charm.
Attatched is a quick test with some of the cowiki classes through poseidon.

oh well looks like they changed all reflection classes names…
i’ll try rc2 and fix all code necessary tomorrow (:

Sike

Ok I tryed it and got it to work… AWESOME!

I decided to get ambitious as do something like say WACT. I used one of the example called BLOCK.php with the program sike has so generously offered and then used posiden to depict the image. You wact guys might get happy about this picture.

It shows a compile in progress, so HTMLSax’s classes are also loaded and diagrammed. This is goiing to be tool of the year. Awesome!

PS: The Zip is a posiden CLASS UML file of the whole scenario… So you only need posiden to view it - if you don;t have php5 and the program set up! Check it out.

hehe nice picture resolution. can’t see that much but it shows
the tool does its job (:

i am currently adjusting stuff to rc2 and impementing properties to show up in the diagrams…

Sike

ok here is the new zip. cleaned some things up a bit and added properties.

Sike

while working with the uml view on my project i realized that
using packages would improve readability so i implemented it (:
this will work only if you use DocBlocks with @package tags.
same for variable types (@param).

Sike

Nice, will look at it tonight.
One thing: how about implementing a couple of const when generating the xmi:


 XMIWriter::CLI = 1;
 XMIWriter::BROWSER = 2; // default
 $xmi->setEnv( XMIWriter::CLI );
 

I use tools likt this in the terminal, and getting lots of html tags there doesn’t do much good.
Maybe a function:


 private function status( $msg )
 {
 	 if( $this->isCli() )
 	 {
 		  echo $msg . "\
";
 	 }
 	 else
 	 {
 		   echo $msg . "<br />";
 	 }
 }
 

then use that function to print the message depending on where you are executing the file. ( I’ll implement this later tonight when I get off work if you don’t want to do it )

good point. never used cli but i will try to implement this feature

Sike

easy enough… i just used follwing code (stolen from an older thread) for checking if we run in cli mode :

$this->cli = (php_sapi_name() == 'cli') ? true : false;

Sike

Sike, I’ve just been using your php2xmi script and it works really well, great! Have you been developing it any further since your last post?

I’ve just come across this which may be of interest to people

that’s just sick, nice work …

nice work