bartlett/graph-plantuml-generator

A PlantUML generator for graph-uml

1.0.0-rc.2 2020-09-10 11:28 UTC

This package is auto-updated.

Last update: 2020-11-10 12:40:12 UTC


README

Latest Stable Version Minimum PHP Version License

bartlett/graph-plantuml-generator

Generate UML diagrams in PlantUML format.

Note: This project is in beta stage! Feel free to report any issues you encounter.

Features

The main features provided by this library are:

  • build UML statements of a class diagram
  • build image in one of the supported formats with local plantuml.jar executable

Install

The recommended way to install this library is through composer. If you don't know yet what is composer, have a look on introduction.

composer require bartlett/graph-plantuml-generator

Additionally, you'll have to install PlantUML jar and Java Runtime (java executable). Users of Debian/Ubuntu-based distributions may simply invoke:

$ sudo apt update
$ sudo apt-get install openjdk-11-jre-headless

while remaining users should install from PlantUML Download page.

You can also use the PlantUML demo server at http://www.plantuml.com/plantuml/uml/

Quick Start

Once installed, you can use the following code to draw an UML class diagram for your existing classes:

<?php

use Bartlett\GraphUml\ClassDiagramBuilder;
use Bartlett\GraphPlantUml\PlantUmlGenerator;

use Graphp\Graph\Graph;

$generator = new PlantUmlGenerator();
$generator->setExecutable('vendor/bin/plantuml');
$graph = new Graph();
$builder = new ClassDiagramBuilder(
    $generator,
    $graph,
    [
        'label_format' => 'default',
    ]
);

$builder->createVertexClass(PlantUmlGenerator::class);

// personalize render
// https://plantuml.com/en/color
$graph->setAttribute('graph.bgcolor', 'transparent');
$graph->setAttribute('cluster.Bartlett\\GraphPlantUml.graph.bgcolor', 'lightsteelblue');
$graph->setAttribute('cluster.Bartlett\\GraphUml\\Generator.graph.bgcolor', 'SteelBlue');

// show UML diagram statements
echo $generator->createScript($graph);
// default format is PNG
echo $generator->createImageFile($graph) . ' file generated' . PHP_EOL;

That should give such output:

Single Class UML

NOTE You can use $generator->getPrefix() (that will return blank, because its not used here), for each setAttribute if you want to keep the same syntax for whatever generator.

Documentation

Full documentation is written in MarkDown format, and HTML export is possible with Daux.io. See output results at http://bartlett.laurent-laville.org/graph-uml/ or raw *.md files in docs folder.

Table of Contents

Resources

Contributors

  • Laurent Laville (Lead Developer)