laradic/dependency-sorter

A dependency sorter package

1.0.0 2017-03-21 23:23 UTC

This package is not auto-updated.

Last update: 2024-10-31 14:50:21 UTC


README

Overview

Simple

use Laradic\DependencySorter\Sorter;

$sorter = new Sorter();

$sorter->add('jquery');
$sorter->add('bootstrap', ['jquery']);
$sorter->add('bootstrap-switch', ['jquery', 'bootstrap']);

$sorted = $sorter->sort();

Using classes

use Laradic\DependencySorter\Dependable;

class Asset implements Dependable {
    
    protected $name;
    
    protected $dependencies = [];
    
    public function __construct($name, array $dependencies = []){
        $this->name = $name;
        $this->dependencies = $dependencies;
    }
    
    public function getDependencies(){
        return $this->dependencies;
    }

    public function getHandle(){
        return $this->name;
    }
}
$jquery = new Asset('jquery');
$bootstrap = new Asset('bootstrap', ['jquery']);
$bootstrapSwitch = new Asset('bootstrap-switch', ['jquery', 'bootstrap']);

$sorter = new \Laradic\DependencySorter\Sorter();
$sorter->add([ $jquery, $bootstrap, $bootstrapSwitch ]);
$sorted = $sorter->sort();