Skip to content
halmhatt edited this page Sep 18, 2012 · 2 revisions

This is how to use Dependencies.

  1. You create an object of the Dependencies class
  2. You add sources/dependencies
  3. You sort them in the right order
<?php
// Require file
require_once('dependencies.php');

// Keeps track of all the dependencies
$dep = new Dependencies();

// Add source that depends on jquery and underscore
$dep -> add('module-name', array('jquery', 'underscore'));

// Add underscore
$dep -> add('underscore')

// Add source that do not depend on anything
$dep -> add('jquery');
	
// Sort the dependencies
$sorted = $dep -> sort();

// Print all the dependencies in the right order
foreach($sorted as $dependency) {
	printf('%s (%s)', $dependency -> name, implode(', ', $dependency -> dependencies));
	echo PHP_EOL;
}
	
/* Results in
	jquery ()
        underscore ()
	module-name (jquery, underscore)
*/
?>

Clone this wiki locally