master |
develop |
---|---|
Samll library to generate an abtract graph out of an object and its dependencies.
You can then visualize this graph by rendering it with graphviz, or you could also run some analysis on it to check boundaries in your app are not crossed (enforce bounded context).
composer require innmind/object-graph
use Innmind\ObjectGraph\{
Graph,
Visualize,
};
$graph = new Graph;
$visualize = new Visualize;
$objectGraph = $graph($theRootObjectOfYourApp); // the object could be the framework instance for example
$os
->control()
->processes()
->execute(
Command::foreground('dot')
->withShortOption('Tsvg')
->withShortOption('o', 'graph.svg')
->withInput($visualize($objectGraph))
)
->wait();
This will generate a graph.svg
file representing the object graph of your application.
use Innmind\ObjectGraph\{
Assert\Acyclic,
Graph,
};
$foo = new Foo;
$bar = new Bar;
$foo->someProperty = $bar;
(new Acyclic)(
(new Graph)($foo)
); // true
$bar->someProperty = $foo;
(new Acyclic)(
(new Graph)($foo)
); // false
Assert that somme class depends on another, useful to make sure decorators are assembled correctly.
use Innmind\ObjectGraph\{
Assert\Stack,
Graph,
};
$requestHandler = new CatchExceptions(
new Debug(
new Security(
new Router($controllers)
)
)
);
$stack = Stack::of(
CatchExceptions::class,
Security::class,
Router::class
);
$stack((new Graph)($requestHandler)); // true
$requestHandler = new Security(
new CatchExceptions(
new Debug(
new Router($controllers)
)
)
);
$stack((new Graph)($requestHandler)); // false as Security is above CatchExceptions
Useful to make sure some bounded context doesnt depend on another.
use Innmind\ObjectGraph\{
Assert\Boundary,
Graph,
};
$boundary = Boundary::of(
'BoundedContext\\Foo', // namespace to protect
'BoundedContext\\Bar',
'BoundedContext\\Baz'
);
$object = new BoundedContext\Foo\SomeClass(
new Indirection(
new BoundedContext\Bar\SomeClass
)
);
$boundary((new Graph)($object)); // false as Foo depends on Bar