innmind / object-graph
Extract object graph out of a root object
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
Small library to generate an abstract graph out of an object and its dependencies.
You can then visualize this graph by rendering it with graphviz.
Installation
composer require innmind/object-graph
Usage
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();
This will generate a graph.svg
file representing the object graph of your application.
Note This example uses
innmind/operating-system
to generate the svg file but the package is not a direct dependency, you can use the content returned by$render()
however you wish.
Note: You can pass an implementation of
RewriteLocation
as the first argument ofRender
so you can rewrite the url to the class file that will be used in the generated graph (useful if you want to generate urls to open the files directly in your IDE).