Modules can be added with {@link addModuleName()}. Edges between these modules
can then be added using {@link addEdge()}. Both ends of an edge must have
been defined before the edge is added.
php
$graph = new DependencyGraph();
$graph->addModuleName('acme/core');
$graph->addModuleName('acme/blog');
$graph->addModuleName('acme/blog-extension1');
$graph->addModuleName('acme/blog-extension2');
$graph->addDependency('acme/blog', 'acme/core');
$graph->addDependency('acme/blog-extension1', 'acme/blog');
$graph->addDependency('acme/blog-extension2', 'acme/blog');
$graph->addDependency('acme/blog-extension2', 'acme/blog-extension1');
You can use {@link getPath()} and {@link hasPath()} to check whether a path
exists from one module to the other:
php
...
$graph->hasPath('acme/blog-extension1', 'acme/blog');
=> true
$graph->hasPath('acme/blog-extension2', 'acme/blog-extension1');
=> false
$graph->getPath('acme/blog-extension2', 'acme/core');
=> array('acme/core', 'acme/blog', 'acme/blog-extension2')
With {@link getSortedModuleNames()}, you can sort the modules such that the
dependencies defined via the edges are respected:
php
...
$graph->getSortedModuleNames();
=> array('acme/core', 'acme/blog', 'acme/blog-extension1', 'acme/blog-extension2')