# PhPuml
[![Packagist](https://img.shields.io/packagist/l/jhofm/ph-puml.svg?style=flat-square)](https://packagist.org/packages/jhofm/ph-puml)
[![Packagist](https://img.shields.io/packagist/v/jhofm/ph-puml.svg?style=flat-square)](https://packagist.org/packages/jhofm/ph-puml)
[![Packagist](https://img.shields.io/packagist/php-v/jhofm/ph-puml.svg?style=flat-square)](https://packagist.org/packages/jhofm/ph-puml)
[![CI Workflow](https://img.shields.io/github/workflow/status/jhofm/ph-puml/CI.svg?style=flat-square)](https://github.com/jhofm/ph-puml/actions)
## About PhPuml
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)
## 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
* Dependencies are inferred from constructor argument types (assumes dependency injection)
* Associations are inferred from "new" expressions (\<\<creates\>\>) and "throw" statements (\<\<throws\>\>)
* Types renderable with fully qualified or short names (independently configurable for interfaces, traits, classes, properties and method arguments)
* Works on Linux (tested), Windows (tested), macOS (probably)
## Installation
The easiest way to install PhPuml is as a composer project.
```bash
$ composer create-project jhofm/ph-puml
```
A [phar](https://www.php.net/manual/en/book.phar.php) version of the tool is created a part of the build process, but currently not reliably downloadable. However with the project already installed,
you can create the phar yourself using [clue/phar-composer](https://github.com/clue/phar-composer).
```bash
$ curl -JL -o phar-composer.phar https://clue.engineering/phar-composer-latest.phar
$ php phar-composer.phar ph-puml
$ php ph-puml.phar
```
## Quick Start
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
```
You can specify a relative or absolute path to a target directory or file as the first argument.
```bash
$ ph-puml mycode/src
```
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 -p /somedir/plantuml.jar -f svg > ~/mycode.svg
```
- or install the optional [jawira/plantuml](https://packagist.org/packages/jawira/plantuml) package
```bash
$ composer create-project jhofm/ph-puml
$ cd ph-puml
$ composer require jawira/plantuml
$ ph-puml /my/code/dir -f svg > ~/mycode.svg
```
### 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.
```bash
$ ph-puml -e -i "/\.php$/" -i "/^includes/.*\.inc$/"
```
The command will fail when attempting to parse files that do not contain valid PHP code.
### Namespaces
Namespaced classes, interfaces and traits are rendered with fully qualified names by default, while property and method argument types are not.
This behaviour can be customized using the `namespaced-types`/`t` option.
```bash
$ ph-puml -t cmp # render all types as FQNs
$ ph-puml -t # render short types only
$ ph-puml -t c # render only classlikes (classes, interfaces & traits) as FQNs
```
### Relations to external types
Relations to types that have not been analyzed are not rendered by default to reduce clutter in the generated diagram.
This included built-in Types like \Exception etc. Add the following option to include these relations.
```bash
$ ph-puml -x false # include relations to types that were not analyzed
```
### Help
PhPuml uses `symfony/command`, so a help page including all supported arguments and options is available.
```bash
$ ph-puml -h
```
Omitting namespaces for classes, interfaces or traits may cause relations to be drawn wrong if unqualified type names are repeated in the analyzed sources.
## Limitations
* Auto generated class diagrams will probably never exactly meet your needs, but provide a starting point for manual refinement (and save mind-numbing work).
* PhPuml is able to handle huge amounts of code files, but limiting diagrams to as few classes as needed is always good idea.
* Cleaner code will yield better results. Type hints and Namespaces help a whole lot, for example.
* There's a lot of polishing still to be done, like inferring additional relation types or providing more customisations.
## Troubleshooting
* `Uncaught Error: Class Composer\InstalledVersions not found`: PhPuml requires Composer 2
* `require(): Failed opening required ...`: Run composer install
## Acknowledgements
This would have been exponentially more difficult to do without [Nikita Popov](https://github.com/nikic)'s [PHP-Parser](https://github.com/nikic/PHP-Parser),
so many thanks for that. [Symfony](https://github.com/symfony) helped a lot, too.
Basically every dependency i use is maintained by kings, queens and total legends. <3
没有合适的资源?快使用搜索试试~ 我知道了~
ph-puml:用于PHP代码的PlantUML类图生成器
共47个文件
php:32个
yml:4个
gitkeep:2个
需积分: 38 3 下载量 103 浏览量
2021-02-04
21:22:17
上传
评论
收藏 66KB ZIP 举报
温馨提示
PhPuml 关于PhPuml PhPuml从PHP代码生成PlantUML类图。 这是该工具本身创建的类图: 产品特点 通过作曲者方便安装 在不安装PlantUML的情况下生成PlantUml文件,或者使用plantuml.jar可执行文件生成所有受支持的格式(png,svg,乳胶等) 命名空间中的软件包 生成类,接口和特征的继承关系 生成类属性和方法签名,包括来自@var doc注释的类型提示 从构造函数参数类型推断依赖关系(假设依赖注入) 从“ new”表达式(<< creates>>)和“ throw”语句(<< throws>>)推断出关联 具有完全限定名或简称的可渲染类
资源详情
资源评论
资源推荐
收起资源包目录
ph-puml-master.zip (47个子文件)
ph-puml-master
.scrutinizer.yml 679B
.github
workflows
ci.yml 3KB
pr.yml 682B
var
log
.gitkeep 0B
cache
.gitkeep 0B
.phpcs.xml 9KB
src
Command
ClassDiagramCommand.php 3KB
Renderer
ClassLikeRenderer.php 8KB
PumlRenderer.php 2KB
IndentedRenderTrait.php 579B
RendererException.php 190B
RelationRenderer.php 3KB
TypeRenderer.php 2KB
Formatter
FormatterException.php 157B
PlantUmlFormatterStrategy.php 2KB
Formatter.php 2KB
FormatterInterface.php 263B
NullFormatterStrategy.php 375B
NodeParser
ClassLikeRegistry.php 1KB
NodeParser.php 2KB
NodeParserException.php 159B
NameResolver.php 8KB
Service
PhPumlService.php 3KB
Relation
TypeGuard.php 990B
RelationInferrer.php 7KB
Relation.php 2KB
Options
OptionInterface.php 620B
Option.php 1KB
OptionsException.php 187B
Options.php 5KB
OptionConfiguration.php 536B
PhPumlException.php 152B
CodeProvider
CodeProvider.php 3KB
CodeProviderException.php 201B
doc
src
ph-puml.puml 10KB
img
ph-puml.svg 129KB
config
services.yml 3KB
LICENSE 1KB
phpunit.xml 651B
README.md 6KB
tests
Fixtures
SelfFactory.php 450B
Relation.php 287B
bootstrap.php 1KB
Integration
ContainerTest.php 1KB
.gitignore 111B
bin
ph-puml 2KB
composer.json 1KB
共 47 条
- 1
应聘
- 粉丝: 27
- 资源: 4568
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0