API

API – How to use PHP_UML from its API?

Principles

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.

Examples

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

<?php
require_once 'PHP/UML.php';

$uml = new PHP_UML();   
$uml->setInput('test.php');
$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

<?php
require_once 'PHP/UML.php';

$uml = new PHP_UML(); 
$uml->setInput(array('C:\Inetpub\foo''C:\Inetpub\libraries'));
$uml->parse();
$uml->export('html''C:\Inetpub\api');
?>

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

<?php
require_once 'PHP/UML.php';

$uml = new PHP_UML();

$uml->setInput('foo.xmi');

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

$uml->parse();

$exporter = new PHP_UML_Output_Php_Exporter();
$exporter->setModel($uml->getModel());
$exporter->export('./');
?>

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

<?php
require_once 'PHP/UML.php';

$importer = new PHP_UML_Input_PHP_FileScanner();
$importer->setDirectories(array('somewhere/'));
$importer->import();

$exporter = new PHP_UML_Output_Xmi_Exporter();
$exporter->setModel($importer->getModel());
$exporter->setXmiVersion(1);
$exporter->setEncoding('utf-8');
$exporter->setDeploymentView(true);
$exporter->setComponentView(true);
$exporter->export('somewhere/else/');
?>

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: Sat, 16 Feb 2019 — 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.