iyoworks/dependency-sorter

该软件包最新版本(dev-develop)没有可用的许可信息。

根据依赖列表排序项

dev-develop 2014-06-04 22:02 UTC

This package is not auto-updated.

Last update: 2024-09-23 16:02:37 UTC


README

根据依赖列表排序项。

此软件包提供2个接口

Iyoworks\DependencySorter\SortableInterface
由执行排序的对象实现
Iyoworks\DependencySorter\DependableInterface
由要排序的对象实现

可以通过 Sorter::add(array) 将项组传递给排序器,或通过 Sorter::addItem(item, dependencies) 单独传递。

提供的 Sorter 实现可以从以下获取依赖项

  • 逗号分隔的字符串
  • 数组
  • 实现 DependableInterface 的对象
$sorter = new Iyoworks\DependencySorter\Sorter;
$sorter->add( array(
	'couple' => 'father, mother'
	'mother' => 'father',
	'father' => null,
	));
$orderedItems = $sorter->sort();

排序后的项目列表将如下所示

Array
(
    [0] => father
    [1] => mother
    [2] => couple
)

缺失依赖项

识别出缺少依赖项的项目。

$sorter = new Iyoworks\DependencySorter\Sorter;
$sorter->add( array(
	'couple' => 'father, mother'
	'mother' => 'child',
	'father' => 'mother',
	) );
$orderedItems = $sorter->sort(); //returns an empty array

可以检索缺失的依赖项

$missing = $sorter->getMissing(); 

缺失的项目将如下所示

Array
(
    [mother] => Array
        (
            [child] => child
        )
)

可以单独检索项目的缺失依赖项

$missing = $sorter->getMissing('mother'); 

您还可以检查项目是否有缺失的依赖项

$sorter->hasMissing($item);

您还可以检查项目是否是缺失的依赖项

$sorter->isMissing($dep);

循环依赖

识别循环依赖。

$sorter = new Iyoworks\DependencySorter\Sorter;
$sorter->add( array(
	'couple' => 'father, mother'
	'mother' => 'father',
	'father' => 'mother',
	) );
$orderedItems = $sorter->sort(); //returns an empty array
$circular = $sorter->getCircular(); 

循环项目的列表将如下所示

Array
(
    [mother] => Array
        (
            [father] => father
        )
    [father] => Array
        (
            [mother] => mother
        )
)

可以单独检索项目的循环依赖。

$circular = $sorter->getCircular('father'); 

您还可以检查项目是否有循环依赖

$sorter->hasCircular($item);

您还可以检查项目是否是循环依赖

$sorter->isCircular($dep);