innmind / object-graph
从根对象中提取对象图
3.2.0
2023-09-17 15:07 UTC
Requires
- php: ~8.1
- innmind/graphviz: ~3.2
- innmind/immutable: ~4.13|~5.0
- innmind/reflection: ~5.0
- innmind/url: ~4.1
Requires (Dev)
- innmind/coding-standard: ~2.0
- phpunit/phpunit: ~9.0
- symfony/var-dumper: ^6.2
- vimeo/psalm: ~5.6
README
一个小型库,用于从对象及其依赖中生成抽象图。
然后您可以通过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,这很有用)。