PHP code example of digilist / dependency-graph

1. Go to this page and download the library: Download digilist/dependency-graph library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

digilist / dependency-graph example snippets


$nodeA = new DependencyNode('A');
$nodeB = new DependencyNode('B');
$nodeC = new DependencyNode('C');
$nodeD = new DependencyNode('D');
$nodeE = new DependencyNode('E');

$nodeA->dependsOn($nodeB);
$nodeA->dependsOn($nodeD);
$nodeB->dependsOn($nodeC);
$nodeB->dependsOn($nodeE);
$nodeC->dependsOn($nodeD);
$nodeC->dependsOn($nodeE);

$graph = new DependencyGraph();
$graph->addNode($nodeA);
$resolved = DependencyGraph->resolve(); // returns [D, E, C, B, A]

$graph = new DependencyGraph();

$nodeA = new DependencyNode('A');
$nodeB = new DependencyNode('B');
$nodeC = new DependencyNode('C');
$nodeD = new DependencyNode('D');
$nodeE = new DependencyNode('E');

$graph->addDependency($nodeA, $nodeB);
$graph->addDependency($nodeA, $nodeD);
$graph->addDependency($nodeB, $nodeC);
$graph->addDependency($nodeB, $nodeE);
$graph->addDependency($nodeC, $nodeD);
$graph->addDependency($nodeC, $nodeE);

$resolved = DependencyGraph->resolve(); // returns [D, E, C, B, A]