innmind/object-graph

从根对象中提取对象图

3.2.0 2023-09-17 15:07 UTC

This package is auto-updated.

Last update: 2024-09-17 17:15:55 UTC


README

Build Status codecov Type Coverage

一个小型库,用于从对象及其依赖中生成抽象图。

然后您可以通过graphviz渲染此图进行可视化。

安装

composer require innmind/object-graph

用法

use Innmind\ObjectGraph\{
    Lookup,
    Render,
    RewriteLocation\SublimeHandler,
};
use Innmind\OperatingSystem\Factory;
use Innmind\Server\Control\Server\Command;

$lookup = Lookup::of();
$render = Render::of(
    new SublimeHandler, // optional, useful to open the file in Sublime Text instead of the browser
);

$objectGraph = $lookup($theRootObjectOfYourApp); // the object could be the framework instance for example

Factory::build()
    ->control()
    ->processes()
    ->execute(
        Command::foreground('dot')
            ->withShortOption('Tsvg')
            ->withShortOption('o', 'graph.svg')
            ->withInput($render($objectGraph)),
    )
    ->wait();

这将生成一个表示您的应用程序对象图的graph.svg文件。

注意 此示例使用innmind/operating-system生成svg文件,但该包不是直接依赖项,您可以使用$render()返回的内容按需使用。

注意:您可以将RewriteLocation的实现作为Render的第一个参数传递,这样您就可以重写用于生成图中使用的类文件的URL(如果您想生成可以直接在您的IDE中打开文件的URL,这很有用)。