Introduction
Описание
PHP_UML converts programming data from one format (PHP or XMI) to another (PHP, XMI or HTML). In other words, PHP_UML is a reverse-engineering tool, and an API documentation tool.
It can parse PHP files, and 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. Two themes are available (an oldie, similar to Javadoc, and a modern looking one)
- PHP code skeletons (useful if you have an existing XMI file, and want to generate the files, folders and class declarations all at once)
From its version 1.5, PHP_UML can also parse procedural code. The export format called "htmlnew" benefits from this new capability, and turns PHP_UML into a kind of competitor of PhpDocumentor (although it does not offer all of its features). See here an example of an API documentation as generated by PHP_UML.
Features
PHP_UML is able to parse the following PHP elements: namespaces, classes, interfaces, properties, and functions. It can also retrieve information from the inline comments, via the annotations: @package
, @var
, @param
-
@param
and@var
learn PHP_UML about the expected types of a parameter or a property (when type hinting is not present). -
@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.
Usage
You can use PHP_UML either from command line (the simplest solution), or by writing a piece of code that relies 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->setInput('tests'); // this defines which files/folders to parse (here, the folder "tests")
$uml->parse('myApp'); // this starts the parser, and gives the name "myApp" to the generated metamodel
$uml->export('xmi', 'myApp.xmi'); // this serializes the metamodel in XMI code, and saves it to a file "myApp.xmi"
?>
About XMI
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. An inline converter (using PHP_UML behind the scene) is available here.