Skip to content

Commit

Permalink
plantuml output formats, runtime options refactored, output path arg
Browse files Browse the repository at this point in the history
  • Loading branch information
jhofm committed Dec 27, 2020
1 parent d541ae8 commit d97f5b5
Show file tree
Hide file tree
Showing 20 changed files with 882 additions and 1,713 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/vendor/
!/var/cache/.gitkeep
/var/cache/*
/*.puml
/*.puml
/composer.lock
85 changes: 56 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

## About PhPuml

PhPuml is a console tool that creates PlantUML class diagram definitions (`*.puml`) from PHP code, written in PHP.
PhPuml generates PlantUML class diagrams from PHP code.

Here's a class diagram of the tool, created by itself:

![PhPuml class diagram](./doc/img/ph-puml.svg)

And the [generated puml file](./doc/src/ph-puml.puml) the diagram is based on.

## Features

* Convenient installation via composer
* Generate PlantUml files without having PlantUML installed or generate all supported formats (png, svg, latex, etc) using a `plantuml.jar` executable
* Packages from Namespaces
* Generates inheritance relationships for classes, interfaces and traits
* Generates class properties & method signatures, including type hints from @var doc comments
Expand All @@ -27,67 +26,95 @@ And the [generated puml file](./doc/src/ph-puml.puml) the diagram is based on.

## Installation

The preferred way to install PhPuml is globally through composer.

```console
$ composer global require jhofm/ph-puml
```

If you already have composer's global vendor/bin folder in your PATH, PhPuml can be executed by calling the script ```ph-puml```.
Otherwise the executable can be found at ``~/.composer/vendor/bin/ph-puml``.
The easiest way to install PhPuml is as a composer project.

Alternatively you can also install PhPuml as a composer project.

```console
```bash
$ composer create-project jhofm/ph-puml
$ ./bin/ph-puml
```

Or clone this repository and install the composer dependencies yourself.
It is also possible to install it globally. This may not work if other globally installed
packages have conflicting dependencies.

```console
$ git clone git@github.com:jhofm/ph-puml.git
$ cd ph-puml
$ composer install
$ ./bin/ph-puml
```
```bash
$ composer global require jhofm/ph-puml
```

## Quick Start

The `ph-puml` script will output PlantUML code describing all PHP files found in the current
folder.
The `ph-puml` script will output PlantUML syntax describing all PHP files found in the current folder when run without any parameters.

```bash
$ cd mycode/src
$ ph-puml
```

Alternatively it accepts a relative or absolute path to a target directory or file as an argument.
You can specify a relative or absolute path to a target directory or file as the first argument.

```bash
$ ph-puml mycode/src
```

The resulting PlantUML code is written to the console's standard output and can of course be piped into a file instead.
The second optional argument is the output path. The console's standard output will be used if none is specified.
The following two commands produce the same result:
```bash
$ ph-puml mycode/src > class.puml
$ ph-puml mycode/src class.puml
```
## Advanced features
### Output formats
PhPuml generates PlantUML puml file syntax by default, but you can also export most output formats supported by PlantUML directly.
Currently, these are:
- eps (Postscript)
- latex (LaTeX/Tikz)
- latex:nopreamble (LaTeX/Tikz without preamble)
- png (PNG image)
- svg (SVG vector image)
- scxml (SCXML state chart, seems broken in PlantUML Version 1.2020.26)
- txt (ASCII art)
- utxt (ASCII art with unicode letters)
- vdx (VDX image)
- xmi (XMI metadata description)
This requires a Java Runtime Environment on the machine running PhPuml. See the [PlantUML guide](https://plantuml.com/starting) for more information.
You also need to either:
- provide a path to a `plantuml.jar` file
```bash
$ ph-puml /my/code/dir --plantuml-path /somedir/plantuml.jar --format svg > ~/mycode.svg
```
- or install the optional [jawira/plantuml](https://packagist.org/packages/jawira/plantuml) package
```bash
$ ph-puml > class.puml
$ composer create-project jhofm/ph-puml
$ cd ph-puml
$ composer require jawira/plantuml
$ ph-puml /my/code/dir --format svg > ~/mycode.svg
```
If the target path is a directory, PhPuml will determine the code files to analyze using a set of inclusion and exclusion rules.
### Path filters
If the input path is a directory, PhPuml will determine the code files to analyze using a set of inclusion and exclusion rules.
By default, files in the directory tree with the file extension `.php` are included, as long as none of their parent folders are called `vendor`.
You can override the filter rules with command line options. All rules are regular expressions. You can use several at the same time.
For example the following command will NOT skip files from `vendor` folders, and analyze files in the `includes` folder with the file extension `.inc` as well.
```console
```bash
$ ph-puml --exclude --include "/\.php$/" --include "/^includes/.*\.inc$/"
```
The command will fail when attempting to parse files that do not contain valid PHP code.
PhPuml uses `symfony/command`, so a help page including all supported arguments and options is available.
```console
```bash
$ ph-puml -h
```
Expand Down
1 change: 1 addition & 0 deletions bin/ph-puml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ $container = (function (): ProjectServiceContainer {
new FileLocator(
dirname(__DIR__) . '/config'));
$loader->load('services.yml');
$containerBuilder->setParameter('root-dir', dirname(__DIR__));
$containerBuilder->compile();
file_put_contents($cachePath, (new PhpDumper($containerBuilder))->dump());
}
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
}
],
"bin": ["bin/ph-puml"],
"require-dev": {
},
"require": {
"ext-json": "*",
"symfony/console": "^5.2",
Expand All @@ -23,6 +21,9 @@
"symfony/config": "^5.2",
"symfony/yaml": "^5.2"
},
"suggest": {
"jawira/plantuml": "For generating output using PlantUML"
},
"autoload": {
"psr-4": {
"Jhofm\\PhPuml\\": "src"
Expand Down
Loading

0 comments on commit d97f5b5

Please sign in to comment.