|
|
(Next) Command line interface |
||||
| |
|||||
|
|||||
PHP_UML is a reverse-engineering tool, and an API's documentation tool.
It can parse PHP files, and immediately generate:
An XMI file, that reflects the object structure of the code parsed (you can then import it into a CASE tool, such as Rational Rose)
A full HTML API documentation, very similar to Javadoc
PHP code skeletons (useful if you have an existing XMI file, and want to generate the files, folders and class declarations all at once)
XMI is an OMG standard for exchanging metadata information via XML, and is commonly used as an interchange format for UML models. Many UML softwares support importing and exporting of XMI files.
Like PhpDocumentor, PHP_UML can parse the following PHP elements: namespaces, classes, interfaces, properties, and functions. It can also retrieve information from the inline comments, via the docblocks: @package, @var, @param
@param and @var learn PHP_UML about the expected types of a parameter or a property.
@package learns PHP_UML about the namespace of an element (even if, from PHP 5.3, it is recommended to use the PHP namespacing instructions instead)
So the more documented your PHP code is, the more precise your XMI file, or your API documentation, will be.
At the current time, the UML/XMI standards exist in two distinct families of versions, 1.x and 2.x. PHP_UML can generate XMI in version 1.4, as well as in version 2.1. Be warned, though, that some UML tools might not interpret accurately the data contained in your XMI file. For example, the link between a UML artifact (a source file) and the classes defined inside that artifact is only available from version 2 of UML.
PHP_UML can also convert existing UML/XMI data from version 1.4 to version 2 (simple conversion).
You can use PHP_UML either from command line, or by writing a piece of code that will rely on PHP_UML.
Parsing a single file test.php, and generating its XMI file:
<?php
require_once 'PHP/UML.php';
$uml = new PHP_UML();
$uml->parseFile('test.php');
$uml->generateXMI(1); // UML version number (1 or 2)
$uml->saveXMI('test.xmi');
?>
Your UML/XMI code might be interpreted differently by the modeling tool you are going to use along with PHP_UML. This is particularly true for the version 2 of UML/XMI. For instance, the Eclipse plug-ins (EMF, Papyrus) only accept a particular flavour of XMI, called ecore, which is only partly compatible with the one you will get with PHP_UML.
PHP_UML is designed with evolution in mind. By choosing XMI as the pivot format for representing the program's structure (namespaces, classes, functions...), PHP_UML can not only interface with many design tools. It can also produce other output formats, via XSL transformations (this is how the HTML documentation is generated).
If you only need to customize a bit the look and feel of the HTML doc, just modify the stylesheet (in /UML/Output/html/resources/style.css).
But if you need deeper changes, you will have to create your own XSL transformation. For that, start with a new folder under /UML/Output/, and put a main.xsl file inside (you can copy the one in /Output/html/). Write all your XSLT stuff in main.xsl, or split it among multiple template files (that's how PHP_UML does). Then run the method PHP_UML->export("newFormat"), by passing the name of your transformation as the first parameter.
Instead of transforming XMI code, another way to create additional output formats would be to write a PHP class that would directly exploit the metamodel that the parser has built, exactly like the package XMI's classes do. That dedicated class should implement PHP_UML_XMI_Builder.
For a better understanding of the program's guts, see its class diagram, available in the docs folder (PHP_UML_class_diagram.png).
If you are interested by the PHP_UML project, and want to participate, do not hesitate to contact me.
|
|
(Next) Command line interface |
||||||||
| |
|||||||||
|
|||||||||