ray / object-visual-grapher
1.0.0
2020-06-19 19:11 UTC
Requires
- php: >=7.1.0
Requires (Dev)
- bear/package: ^1.9.6
- doctrine/annotations: ^1.8
- friendsofphp/php-cs-fixer: ^2.11
- phpmd/phpmd: ^2.6
- phpstan/phpstan: ^0.12.5
- phpunit/phpunit: ^8.5
- ray/di: ^2.10|2.x-dev
- squizlabs/php_codesniffer: ^3.2
This package is auto-updated.
Last update: 2024-08-29 08:19:39 UTC
README
使用ObjectGrapher可视化Ray.Di应用程序
图示器
当你编写了一个复杂的应用程序时,Ray.Di的丰富内省API可以详细描述对象图。这个图示器将此数据以易于理解的可视化形式展示出来。它可以在统一的图中展示复杂应用程序中几个类之间的绑定和依赖关系。
安装
您可以使用composer安装ObjectGrapher
composer --dev require ray/object-visual-grapher
生成.dot文件
Ray.Di的图示器大量依赖于GraphViz,这是一个开源的图形可视化软件包。它干净地分离了图形规范与可视化布局。要为Injector生成一个图形.dot
文件,可以使用以下代码
use Ray\ObjectGrapher\ObjectGrapher; $dot = (new ObjectGrapher)(new FooModule); file_put_contents('path/to/file', $dot);
该.dot文件
执行上述代码将生成一个指定图形的.dot
文件。文件中的每个条目都代表图形中的一个节点或边。以下是一个示例.dot
文件
digraph injector { graph [rankdir=TB]; dependency_BEAR_Resource_ResourceInterface_ [style=dashed, margin=0.02, label=<<table cellspacing="0" cellpadding="5" cellborder="0" border="0"><tr><td align="left" port="header" bgcolor="#ffffff"><font color="#000000">BEAR\\Resource\\ResourceInterface<br align="left"/></font></td></tr></table>>, shape=box] dependency_BEAR_Resource_FactoryInterface_ [style=dashed, margin=0.02, label=<<table cellspacing="0" cellpadding="5" cellborder="0" border="0"><tr><td align="left" port="header" bgcolor="#ffffff"><font color="#000000">BEAR\\Resource\\FactoryInterface<br align="left"/></font></td></tr></table>>, shape=box] dependency_BEAR_Resource_ResourceInterface_ -> class_BEAR_Resource_Resource [style=dashed, arrowtail=none, arrowhead=onormal] dependency_BEAR_Resource_FactoryInterface_ -> class_BEAR_Resource_Factory [style=dashed, arrowtail=none, arrowhead=onormal]
渲染.dot文件
为您的平台下载Graphviz查看器,并使用它来渲染.dot
文件。
在Linux上,您可以使用命令行工具dot
将.dot
文件转换为图像。
dot -T png my_injector.dot > my_injector.png
图形显示
边
- 实线边表示实现到其依赖类型的依赖关系。
- 虚线边表示类型到其实现的绑定。
- 双箭头表示绑定或依赖关系指向一个
Provider
。
节点
- 实现类型具有黑色背景。
- 实现实例具有灰色背景。