2017 © Pedro Peláez
 

library topsort

Topological sorting implementation in PHP

image

pustato/topsort

Topological sorting implementation in PHP

  • Friday, September 8, 2017
  • by pustato
  • Repository
  • 1 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Topological Sort in PHP

Simple Topological Sorting (aka Dependency Resolution) algorithm implementation in PHP., (*1)

Install

composer require pustato/topsort

Example usage

Implement interface \Pustato\TopSort\Contracts\Sortable:, (*2)

// in SiteAsset.php
class SiteAsset implements Pustato\TopSort\Contracts\Sortable
{

    public function getId()
    {
        return static::class;
    }

    public function getDependencies()
    {
        return [
            JQueryAsset::class, BootstrapAsset::class
        ];
    }

    ...
    // Asset implementation
}
// in BootstrapAsset.php
class BootstrapAsset implements Pustato\TopSort\Contracts\Sortable 
{

    public function getId()
    {
        return static::class;
    }

    public function getDependencies()
    {
        return [
            JQueryAsset::class
        ];
    }

    ...
    // Asset implementation
}
// in JQueryAsset.php
class JQueryAsset implements Pustato\TopSort\Contracts\Sortable 
{

    public function getId()
    {
        return static::class;
    }

    public function getDependencies()
    {
        return [];
    }

    ...
    // Asset implementation
}

Add all sortable classes to \Pustato\TopSort\Collection and sort them:, (*3)

$assetsCollection = new \Pustato\TopSort\Collection([
    new SiteAsset(), new JQueryAsset(), new BootstrapAsset()
]);
$result = $assetsCollection->getSorted();
var_dump($result);

And you will get:, (*4)

array(3) {
  [0] => class JQueryAsset#1 (0) {}
  [1] => class BootstrapAsset#2 (0) {}
  [2] => class SiteAsset#3 (0) {}
}

The Versions

08/09 2017

dev-master

9999999-dev

Topological sorting implementation in PHP

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Alexander Atamanov

08/09 2017

v1.0.1

1.0.1.0

Topological sorting implementation in PHP

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Alexander Atamanov

07/03 2017

v1.0.0

1.0.0.0

Topological sorting implementation in PHP

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Alexander Atamanov