PHP code example of sweetchuck / cdd

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

    

sweetchuck / cdd example snippets




declare(strict_types = 1);

use Sweetchuck\cdd\CircularDependencyDetector;

$detector = new CircularDependencyDetector();

$items = [
    // Item "a" has no any dependencies.
    'a' => [],

    // Item "b" depends on "c" and "d".
    'b' => ['c', 'd'],

    // Item "c" has no any dependencies.
    'c' => [],

    // Item "d" has no any dependencies.
    'd' => [],
];

$loops = $detector->detect($items);

/**
 * $loops = [];
 */
var_dump($loops);

$items = [
    // Item "a" depends on "b".
    'a' => ['b'],

    // Item "b" depends on "a".
    'b' => ['a'],
];

$loops = $detector->detect($items);

/**
 * $loops = [
 *   'a|b' => ['b', 'a', 'b'],
 * ];
 */
var_dump($loops);

$items = [
    // Item "a" depends on "b".
    'a' => ['b'],

    // Item "b" depends on "c".
    'b' => ['c'],

    // Item "c" depends on "a".
    'c' => ['a'],
];

$loops = $detector->detect($items);

/**
 * $loops = [
 *   'a|b|c' => ['c', 'a', 'b', 'c'],
 * ];
 */
var_dump($loops);