PHP code example of heptacom / dependency-resolver

1. Go to this page and download the library: Download heptacom/dependency-resolver 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/ */

    

heptacom / dependency-resolver example snippets


$tree  = [
    'A' => [],
    'B' => ['A'],
    'C' => ['B'],
    'D' => ['C', 'A'],
    'E' => ['C', 'B'],
];
$resolution = (new \Heptacom\DependencyResolver\DependencyResolver())->resolve($tree);
print($resolution);
// ['A','B','C','D','E']

$tree  = [
    'A' => ['B'],
    'B' => ['C'],
    'C' => ['A'],
];
$resolution = (new \Heptacom\DependencyResolver\DependencyResolver())->resolve($tree);
// RuntimeException : Circular dependency: C -> A