PHP code example of laradic / dependency-sorter

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

    

laradic / dependency-sorter example snippets


use Laradic\DependencySorter\Sorter;

$sorter = new Sorter();

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

$sorted = $sorter->sort();

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