laradic / dependency-sorter by radic

A dependency sorter package
351
1
2
Package Data
Maintainer Username: radic
Maintainer Contact: info@laradic.nl (Laradic)
Package Create Date: 2017-03-21
Package Last Update: 2018-03-04
Language: PHP
License: proprietary
Last Refreshed: 2024-11-09 15:01:38
Package Statistics
Total Downloads: 351
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 1
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

Overview

| Method | Description | |:-------|:------------| | add($items,$allowNumericitem=false) | add | | addItem($item,$_deps=null) | addItem | | sort | sort | | setItem($item,$_deps) | setItem | | prepNewItem($item,$_deps) | prepNewItem | | satisfied($item) | satisfied | | setSorted($item) | setSorted | | exists($item) | exists | | removeDependents($item) | removeDependents | | setCircular($item,$item2) | setCircular | | setMissing($item,$item2) | setMissing | | setFound($item,$item2) | setFound | | isSorted($item) | isSorted | | requiredBy($item) | | | isDependent($item,$item2) | isDependent | | hasDependents($item) | hasDependents | | hasMissing($item) | hasMissing | | isMissing($dep) | isMissing | | hasCircular($item) | hasCircular | | isCircular($dep) | isCircular | | getDependents($item) | getDependents | | getMissing($str=null) | getMissing | | getCircular($str=null) | getCircular | | getHits($str=null) | getHits |

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();