PHP UML 生成器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/393603/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 22:36:11  来源:igfitidea点击:

PHP UML Generator

phpumlclass-diagram

提问by Jeffrey04

How do I generate UML diagram based on existing classes in PHP?

如何根据 PHP 中的现有类生成 UML 图?

回答by kguest

There's also the PHP UML tool available from pear.

pear还提供了 PHP UML 工具。

PHP_UML:

PHP_UML:

  • Can generate UML/XMI files in version 1.4, or in version 2.1 (logical, component, and deployment views)
  • Can generate an API documentation in HTML format
  • Can generate PHP code (code skeleton) from a given XMI file
  • Can convert UML/XMI content from version 1.4 to version 2.1
  • 可以在 1.4 版或 2.1 版(逻辑、组件和部署视图)中生成 UML/XMI 文件
  • 可以生成 HTML 格式的 API 文档
  • 可以从给定的 XMI 文件生成 PHP 代码(代码框架)
  • 可以将 UML/XMI 内容从 1.4 版转换为 2.1 版

Install it on the command line via:

通过以下方式在命令行上安装它:

$ pear install pear/php_uml

$ pear install pear/php_uml

(This used to be $ pear install pear/php_uml-alphabut the package has since gone stable.)

(这曾经是,$ pear install pear/php_uml-alpha但包已经稳定了。)

Generate your xmi:

生成你的 xmi:

$ phpuml -o project.xmi

$ phpuml -o project.xmi

回答by kguest

I strongly recommend BOUMLwhich:

我强烈推荐BOUML,它:

  • is extremely fast (fastest UML tool ever created, check out benchmarks),
  • has rock solid PHP import and exportsupport (also supports C++, Java, Python)
  • is multiplatform (Linux, Windows, other OSes),
  • is full featured, impressively intensively developed (look at development history, it's hard to believe that such fast progress is possible).
  • supports plugins, has modular architecture (this allows user contributions, looks like BOUML community is forming up)
  • 非常快(有史以来最快的 UML 工具,请查看基准测试),
  • 具有坚如磐石的PHP 导入和导出支持(还支持 C++、Java、Python)
  • 是多平台的(Linux、Windows、其他操作系统),
  • 功能齐全,开发密集程度令人印象深刻(看看开发历史,很难相信这么快的进展是可能的)。
  • 支持插件,具有模块化架构(这允许用户贡献,看起来 BOUML 社区正在形成)

回答by Anthony Hatzopoulos

phUML

phUML

phUML is fully automatic UML class diagramm generator written in PHP, licensed under the BSD license. It is capable of parsing any PHP5 object oriented source code and create an appropriate image representation of the oo structure based on the UML specification.

phUML 是用 PHP 编写的全自动 UML 类图生成器,在 BSD 许可下获得许可。它能够解析任何 PHP5 面向对象的源代码,并根据 UML 规范创建 oo 结构的适当图像表示。

UML Example

UML 示例

./phuml -r /var/www/my_project -graphviz -createAssociations false -neato out.png

Step by step guide

分步指南

回答by ax.

the best (Windows) software i have found to do PHP and UML is Sparx SystemsEnterprise Architect. besides a pletora of features, it supports the followingfor PHP:

我发现做 PHP 和 UML 的最佳(Windows)软件是Sparx Systems Enterprise Architect。除了众多功能外,它还支持PHP的以下功能:

  • Reverse engineer object oriented PHP into UML class diagrams
  • Generate PHP class definitions from UML class diagrams
  • Synchronize changes made in a UML class into the corresponding PHP class definition
  • Synchronize changes made in a PHP class definition into the corresponding UML class
  • Create UML sequence diagrams to show what PHP classes use and how they are used
  • Produce detailed documentation of your PHP code in standard RTF and HTML format
  • Perform code engineering on models to generate base PHP pages.
  • 将面向对象的 PHP 逆向工程为 UML 类图
  • 从 UML 类图中生成 PHP 类定义
  • 将 UML 类中所做的更改同步到相应的 PHP 类定义中
  • 将 PHP 类定义中所做的更改同步到相应的 UML 类中
  • 创建 UML 序列图以显示 PHP 类使用什么以及如何使用它们
  • 以标准 RTF 和 HTML 格式生成 PHP 代码的详细文档
  • 对模型执行代码工程以生成基本 PHP 页面。

not free ($199), but definitely worth the money.

不是免费的(199 美元),但绝对物有所值。

回答by Vinko Vrsalovic

Have you tried Autodiayet? Last time I tried it it wasn't perfect, but it was good enough.

你试过Autodia了吗?上次我试过它并不完美,但已经足够好了。

回答by troelskn

There's also php2xmi. You have to do a bit of manual work, but it generates all the classes, so all you have to do is to drag them into a classdiagram in Umbrello.

还有php2xmi。您必须做一些手动工作,但它会生成所有类,因此您要做的就是将它们拖到Umbrello 中的类图中

Otherwise, generating a diagram with the use of reflection and graphviz, is fairly simple. I have a snippet over here, that you can use as a starting point.

否则,使用反射和 graphviz 生成图表相当简单。我在这里有一个片段,您可以将其用作起点。

回答by Mikko Rantalainen

Here's how I did it (directly from code to PDF drawing without manual drawing of anything):

这是我是如何做到的(直接从代码到 PDF 绘图,无需手动绘制任何内容):

  1. Use BOUMLfor "reverse engineering PHP code" [sic] to extract the class model (BOUML is available from "universe" repository of Ubuntu). I seriously recommend BOUML for this step because it's really fast compared to many other programs I have tried. In addition, it seems that BOUML seems to extract the model correctly (for the parts that BOUML even tries to extract).
  2. Use BOUML to export model as XMI 1.4 file
  3. Use ArgoUMLto import said XMI file (you can use webstart version for this step)
  4. Export XMI from ArgoUML (I don't know which XMI version/variant the output is but it is not the same result as the output from BOUML. The argouml-graphviz cannot handle XMI file directly from BOUML).
  5. Use argouml-graphvizto convert ArgoUML exported XMI file to dot format (you may need to use saxoninstead of xsltproc to get it work due to use of XSLT2)
  6. Use dotor fdpor sfdpto render the class diagram.
  1. 使用BOUML进行“逆向工程 PHP 代码”[原文如此] 来提取类模型(BOUML 可从 Ubuntu 的“universe”存储库中获得)。我在这一步认真推荐 BOUML,因为与我尝试过的许多其他程序相比,它真的很快。此外,似乎 BOUML 似乎正确地提取了模型(对于 BOUML 甚至试图提取的部分)。
  2. 使用 BOUML 将模型导出为 XMI 1.4 文件
  3. 使用ArgoUML导入该 XMI 文件(此步骤可以使用 webstart 版本)
  4. 从 ArgoUML 导出 XMI(我不知道输出是哪个 XMI 版本/变体,但它与 BOUML 的输出结果不同。argouml-graphviz 无法直接从 BOUML 处理 XMI 文件)。
  5. 使用argouml-graphviz将 ArgoUML 导出的 XMI 文件转换为点格式(由于使用 XSLT2,您可能需要使用saxon而不是 xsltproc 才能使其工作)
  6. 使用dotfdpsfdp来呈现类图。

Here's an example of suitable command line for using fdp to output PDF diagram (assuming that dot file generated by argouml-graphviz XLST processing is saved as xmi-model.dot):

以下是使用 fdp 输出 PDF 图的合适命令行示例(假设 argouml-graphviz XLST 处理生成的点文件保存为 xmi-model.dot):

fdp -Tpdf -Gmaxiter=1000 -Gmindist=0.5 -Gpackmode=node \
  -Eweight=0.05 -Elen=1.0 -Eminlen=1.0 -Gsplines=true \
  -Goverlap=false xmi-model.dot -oxmi-model.pdf

As an alternative you could try PHP_UMLor php2xmiinstead of BOUML for doing the "reverse engineering" part. I haven't yet tried that.

作为替代方案,您可以尝试使用PHP_UMLphp2xmi而不是 BOUML 来执行“逆向工程”部分。我还没有尝试过。

(I'm using the phrase "reverse engineering" because it seems that UML people are using those words when they mean extracting class and method information from the source code. I would personally interpret those words as extracting information from executable binary file or captured raw wire data.)

(我使用“逆向工程”这个词是因为当 UML 人员的意思是从源代码中提取类和方法信息时,他们似乎在使用这些词。我个人将这些词解释为从可执行二进制文件中提取信息或捕获的原始数据线数据。)

If you prefer drawing the class diagram by hand (instead of using computer to do all the drawing), you can use either BOUML or ArgoUML for the drawing. Using the "reverse engineered" data via BOUML will help in that case.

如果您更喜欢手工绘制类图(而不是使用计算机进行所有绘制),您可以使用 BOUML 或 ArgoUML 进行绘制。在这种情况下,通过 BOUML 使用“逆向工程”数据将有所帮助。

回答by David Lundquist

If you are looking to generate UML easily from your existing PHP Classes you might want to consider PHPStorm 3.0 IDE. It does a good job of replicating existing code into UML.

如果您希望从现有的 PHP 类轻松生成 UML,您可能需要考虑 PHPStorm 3.0 IDE。它在将现有代码复制到 UML 方面做得很好。

Have a look at the PHP Storm feature list.

查看PHP Storm 功能列表

回答by Hendra Uzia

You can use Visual Paradigm for UML. This might not be the best paid (it's US$699) product, just as an option if anyone would like to try. It can create class diagram from PHP and vice versa, and not only PHP, there's a bunch of language you can choose such as C#, C++, Ruby, Java, VB.NET, Python, Objective C, Perl, etc. There's also a trial you can check on.

您可以将 Visual Paradigm 用于 UML。这可能不是最好的支付(699 美元)产品,如果有人想尝试,这只是一个选项。它可以从 PHP 创建类图,反之亦然,不仅是 PHP,还有很多语言可以选择,例如 C#、C++、Ruby、Java、VB.NET、Python、Objective C、Perl 等。还有一个试用,你可以检查。

回答by Lukas Lukac

In theory you can use PhpStorm to visualise your classes using UML. The generation is not really great but you can effectively refactor stuff and again, at least preview parents, implementations, constants, attributes, methods and their visibility in a nice way.

理论上,您可以使用 PhpStorm 使用 UML 来可视化您的类。这一代不是很好,但你可以有效地重构东西,至少以一种很好的方式预览父项、实现、常量、属性、方法及其可见性。

Situation

情况

I want to visualise a communication between already existing components to a colleague.

我想将现有组件之间的通信可视化为同事。

Process using PHPStorm

使用 PHPStorm 处理

https://blog.jetbrains.com/phpstorm/2017/09/uml-diagrams-in-phpstorm-2017-2/

https://blog.jetbrains.com/phpstorm/2017/09/uml-diagrams-in-phpstorm-2017-2/

Advantages

好处

  • Nice UI, final diagram.
  • Able to refactor code from a diagram.
  • Able to add notes.
  • The class diagram symbolises private/public properties, constructors, methods nicely.
  • 漂亮的用户界面,最终图。
  • 能够从图中重构代码。
  • 可以添加注释。
  • 类图很好地象征了私有/公共属性、构造函数、方法。

Disadvantages

缺点

  • No support for PHP 7.
  • Painfully to use. Can't resize the generated boxes.
  • When adding a new relation, the previous ones get randomly lost :O wtf?
  • Restarting PhpStorm destroys the diagrams
  • Changed my mind, impossible to use relations
  • 不支持 PHP 7。
  • 使用起来很痛苦。无法调整生成的框的大小。
  • 添加新关系时,以前的关系会随机丢失:O wtf?
  • 重启 PhpStorm 会破坏图表
  • 改变了主意,无法使用关系

Result

结果

Anyway, after some painful hour of work I was only able to generate unrelated boxes and had to use additional program to link relations. Really bad. But I believe once they make it work properly it will be a great feature because as the code changes, the diagrams would be automatically updated!

无论如何,经过一些痛苦的工作后,我只能生成不相关的框,并且不得不使用其他程序来链接关系。特别糟糕。但我相信一旦他们让它正常工作,这将是一个很棒的功能,因为随着代码的变化,图表会自动更新!

For now, don't use PhpStorm for UML diagrams.

现在,不要将 PhpStorm 用于 UML 图。