API – How to use PHP_UML from its API?


PHP_UML is structured in 4 packages:

  • The host package, which contains the main class (PHP_UML) and some utility classes
  • The Input package, where the PHP and XMI parser reside (they are the Importer objects).
  • The Metamodel package, which contains the data structures that PHP_UML is using to modelize the code parsed
  • The Output package, which contains all the objects (called Exporter) to transform the UML model stored into memory into an output format (like XMI, HTML, or PHP)

If the default settings suit your needs, the only single class you need to know about is PHP_UML. For more advanced operations, you must use the Importer and Exporter hierarchies of objects, whose roles, respectively, are to import data into the UML model, and export data out from the UML model.


Parsing of a single file test.php, and generation of its XMI file:

require_once 'PHP/UML.php';

$uml = new PHP_UML();   
$uml->parse('foo');                 // parses, and sets the name of the root package
$uml->export('xmi''test.xmi');    // first param is the format (html, php, htmlnew or xmi), second param is the output folder

Parsing of two directories, ignoring the CSV folders, and generation of HTML documentation

require_once 'PHP/UML.php';

$uml = new PHP_UML(); 

Import of an XMI file, and generation of PHP code templates

require_once 'PHP/UML.php';

$uml = new PHP_UML();


$uml->setImporter(new PHP_UML_Input_XMI_FileScanner());   // by default, PHP_UML uses a PHP_UML_Input_PHP_FileScanner


$exporter = new PHP_UML_Output_Php_Exporter();

Parsing of a PHP directory, followed by an XMI generation, without relying on a PHP_UML object

require_once 'PHP/UML.php';

$importer = new PHP_UML_Input_PHP_FileScanner();

$exporter = new PHP_UML_Output_Xmi_Exporter();

Note how the model is transfered from the importer object to the exporter object, with the methods getModel() and setModel().

You can use the factory method PHP_UML_Output_Exporter::getInstance($format) to get an exporter object given a format name, instead of instantiating the objects by yourself.

Things to know about how PHP_UML parses PHP code (Previous) How to extend PHP_UML? (Next)
Last updated: Mon, 20 Feb 2017 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.