PHP_UML
Abstract
PHP_UML is a reverse-engineering tool, and a documentation tool.
Practically, with PHP_UML, you can feed a modelling
design tool, like Rational Rose or Argouml, with an UML representation of
existing PHP source code. This way you get an immediate
overview of an application, with all the usual functions of
a software design tool, like class diagrams exportation, refactoring of
object-oriented applications, or automatic code generation.
PHP_UML is three parts :
- It is a PHP parser
- It is a PHP metamodel, based on MOF (a standard of the Object Management Group)
- It is an XMI code generator (most UML softwares can import XMI
code, this is how you will get the object model of your PHP application
into your design tool)
What does it generate ?
PHP_UML generates a logical view (composed of the packages and classes found),
a component view, and a deployment view (a mapping of the physical filesystem).
Other UML elements will be available in future releases.
Usage
PHP_UML does not provide any graphical interface, although
PhpDocumentor could easily been interfaced with it.
First, let's create a PHP_UML object:
$p = new PHP_UML;
Then, let's parse recursively a directory:
$p->parseDirectory('.'); // we
will parse the current directory
Now, we run the XMI generation:
$p->generateXMI(1); // we choose
XMI version 1 (version 2.1 is also available)
We save the resulting XMI code somewhere:
$p->saveXMI('my_XMI_file.xmi');
That's done ! You can now import my_XMI_file.xmi into your
favourite UML design tool !
Other options are available, see the documentation enclosed in
the PEAR Package.
Source code and download
PHP_UML is a PEAR package. Use the PEAR installer to install it properly on your system.
Alternatively, you can download it from Sourceforge.
Features
- Reads classes, interfaces, inheritance and implementation relations
- Reads properties, class constants, visibility and static attributes
- Reads functions, their parameters, their default values, their types (when stated)
- Reads docblocks : class comments (@package), method comments (@param and @return) and header file comments (@package)
- Interprets the new PHP instructions
namespace and use
- Can attempt to guess the types of the elements, through their default values
- Generates XMI version 1.3, and version 2.1 (version 2.1 is minimal, profiles are not yet supported)
- Generates both logical and physical views
What can I do with PHP_UML ?
You can parse directories of PHP code, and get an XMI file containing all the packages/classes found.
You can import that XMI file into an UML modeling design tool, and get a logical view (your packages/classes/interfaces...)
as well as a component and/or deployment view (files are mapped to artifacts and/or components, and directories are mapped
to subsystems and/or packages).
The relationship between a particular class and the PHP source file where it is defined (that is, an artifact in a deployment view) is rendered through
UML2 manifestations. If your UML CASE tool is UML2 compatible, it should create the association between the class and the artifact correctly.
Read here for more details about the internal implementation.
Read here for a discussion about packages
and namespaces management in PHP_UML.
Tools compatible with PHP_UML
MOF/UML/XMI are complex standards, and they have changed a lot from version 1 to 2.
Depending on the UML software you are going to use along with PHP_UML,
some aspects of your XMI might be interpreted differently, or even ignored.
You may have to disable some options (in PHP_UML, or in your software) for the import to work.
Note: class diagrams are generally not automatically generated by modeling programs. You will have to manually drag and drop your classes (from the class tree view) into a blank class diagram.
ArgoUML
http://argouml.tigris.org/
OPEN SOURCE
UML version : 1.4
Appreciation : An intuitive and flexible soft, but you might possibly get indisposed by its look and feel. Poor performance with big projects.
Compatibility : Imports correctly the files as components in a hierarchical component/subsystem view.
Bouml
http://bouml.free.fr/
OPEN SOURCE
UML version : 2.1
Appreciation : Very good layout, good performance.
Compatibility : Only UML version 2.1. You should find your PHP pages as artefacts in a deployment view,
as well as the source filename in the textual description of your classes.
All the PHP files should be visible in a component view
Papyrus
http://www.papyrusuml.org/
OPEN SOURCE
UML version : 2.1
Appreciation : not the fastest, cannot export diagrams or generate code without other plug-ins...
but available as an Eclipse plug-in !
Compatibility : Papyrus works with a particular flavour of XMI 2 (ecore) but you should be able to import
XMI by doing the following :
- Create a blank model in Papyrus
- Save it
- Papyrus created two files on the disk : one with the extension .di2 (the one to open later in Papyrus),
and one with the extension .uml (containing the UML definitions, required by xxx.di2)
- Copy the xmi you have generated with PHP_UML WITHOUT the enclosing "uml:Model", and paste it into your
file xxx.uml, INTO its own "uml:Model"
- Open xxx.di2
- You should see your UML elements in your UML objects tree view
Umbrello
http://uml.sourceforge.net/
OPEN SOURCE
UML version : 1.4
Appreciation : a tool for Linux (KDE). Quite colorful.
Compatibility : you MUST disable the filename inclusion : $t->$tagFilename = false;
Protégé
http://protege.stanford.edu/
OPEN SOURCE
UML version : 1.3
Protégé is not a UML tool, but an ontology editor.
Rational Rose
http://www-306.ibm.com/software/awdtools/developer/rose/index.html
PROPRIETARY
UML version : 1.4
Appreciation : THE reference in UML design
Compatibility : no artefacts in class packages.
File system in a component view : ok.
Poseidon
http://www.gentleware.com/products.html
PROPRIETARY
Untested
Todo list
Depending on the class:
PHP_UML_XMI_Builder:
- XHTML Documentation generation, via XSLT (ongoing)
- Generation of UML:Profiles (for XMI version 2.1)
- Improvements of datatypes and stereotypes management
- Special implementation for the ecore tools (Eclipse platform) ?
- Internally, replacing the string concatenation by a DOM-XML generation ?
Links
Baptiste Autin, April 2008