ray/object-visual-grapher

Maintainers

👁 koriym

Package info

github.com/ray-di/Ray.ObjectGrapher

pkg:composer/ray/object-visual-grapher

Statistics

Installs: 450 320

Dependents: 1

Suggesters: 0

Stars: 7

Open Issues: 0

1.0.0 2020-06-19 19:11 UTC

Requires

  • php: >=7.1.0

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT f512aef5fc13a41771805c5c0cc4027d09b98c3a

  • Akihito Koriyama <akihito.koriyama.woop@gmail.com>

This package is auto-updated.

Last update: 2026-06-29 01:52:21 UTC


README

Using ObjectGrapher to visualize Ray.Di applications

👁 fake

Grapher

When you've written a sophisticated application, Ray.Di's rich introspection API can describe the object graph in detail. This grapher exposes this data as an easily understandable visualization. It can show the bindings and dependencies from several classes in a complex application in a unified diagram.

Installation

You can install the ObjectGrapher with composer:

composer --dev require ray/object-visual-grapher

Generating a .dot file

Ray.Di's grapher leans heavily on GraphViz, an open source graph visualization package. It cleanly separates graph specification from visualization and layout. To produce a graph .dot file for an Injector, you can use the following code:

use Ray\ObjectGrapher\ObjectGrapher;

$dot = (new ObjectGrapher)(new FooModule);
file_put_contents('path/to/file', $dot);

The .dot file

Executing the code above produces a .dot file that specifies a graph. Each entry in the file represents either a node or an edge in the graph. Here's a sample .dot file:

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]

Rendering the .dot file

Download a Graphviz viewer for your platform, and use it to render the .dot file.

On Linux, you can use the command-line dot tool to convert .dot files into images.

 dot -T png my_injector.dot > my_injector.png

Graph display

Edges:

  • Solid edges represent dependencies from implementations to the types they depend on.
  • Dashed edges represent bindings from types to their implementations.
  • Double arrows indicate that the binding or dependency is to a Provider.

Nodes:

  • Implementation types are given black backgrounds.
  • Implementation instances have gray backgrounds.

This document is mostly taken from https://github.com/google/guice/wiki/Grapher.