PHP code example of mike-roetgers / dependency-graph

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

    

mike-roetgers / dependency-graph example snippets


$op1 = new GenericOperation(1);
$op2 = new GenericOperation(2);
$op3 = new GenericOperation(3);
$op4 = new GenericOperation(4);

$dm = new DependencyManager();
$dm->addOperation($op1)->addOperation($op2)->addOperation($op3)->addOperation($op4);

$dm->addDependencyByOperation($op1, $op2);
$dm->addDependencyByOperation($op1, $op3);
$dm->addDependencyByOperation($op2, $op4);
$dm->addDependencyByOperation($op3, $op4);

$operations = $dm->getExecutableOperations(); // 1
$dm->markAsExecuted($op1);
$operations = $dm->getExecutableOperations(); // 2 and 3
$dm->markAsExecuted($op3);
$operations = $dm->getExecutableOperations(); // 2
$dm->markAsExecuted($op2);
$operations = $dm->getExecutableOperations(); // 4

$op1 = new GenericOperation(1);
$op2 = new GenericOperation(2);
$op3 = new GenericOperation(3);

$dm = new DependencyManager();
$dm->addOperation($op1)->addOperation($op2)->addOperation($op3);

$dm->addDependencyByOperation($op1, $op2);
$dm->addDependencyByOperation($op2, $op3);
$dm->addDependencyByOperation($op3, $op1);

$setupOperation1 = new GenericOperation('Setup1');
$setupOperation1->addTag('setup');
$setupOperation2 = new GenericOperation('Setup2');
$setupOperation2->addTag('setup');

$downstreamOperation = new GenericOperation('Downstream');

$dm = new DependencyManager();
$dm->addOperation($setupOperation1)->addOperation($setupOperation2)->addOperation($downstreamOperation);

$dm->addDependencyByTag('setup', $downstreamOperation); // execute all setup operations first

$dm->addDependencyByTag($downstreamOperation, 'setup'); // downstream is a dependency for all operations tagged with "setup"