|
|
|
@ -23,9 +23,10 @@ class PackageSorter
|
|
|
|
|
* Packages of equal weight are sorted alphabetically
|
|
|
|
|
*
|
|
|
|
|
* @param PackageInterface[] $packages
|
|
|
|
|
* @param array<string, int> $weights Pre-set weights for some packages to give them more (negative number) or less (positive) weight offsets
|
|
|
|
|
* @return PackageInterface[] sorted array
|
|
|
|
|
*/
|
|
|
|
|
public static function sortPackages(array $packages)
|
|
|
|
|
public static function sortPackages(array $packages, array $weights = array())
|
|
|
|
|
{
|
|
|
|
|
$usageList = array();
|
|
|
|
|
|
|
|
|
@ -41,7 +42,7 @@ class PackageSorter
|
|
|
|
|
}
|
|
|
|
|
$computing = array();
|
|
|
|
|
$computed = array();
|
|
|
|
|
$computeImportance = function ($name) use (&$computeImportance, &$computing, &$computed, $usageList) {
|
|
|
|
|
$computeImportance = function ($name) use (&$computeImportance, &$computing, &$computed, $usageList, $weights) {
|
|
|
|
|
// reusing computed importance
|
|
|
|
|
if (isset($computed[$name])) {
|
|
|
|
|
return $computed[$name];
|
|
|
|
@ -53,7 +54,7 @@ class PackageSorter
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$computing[$name] = true;
|
|
|
|
|
$weight = 0;
|
|
|
|
|
$weight = isset($weights[$name]) ? $weights[$name] : 0;
|
|
|
|
|
|
|
|
|
|
if (isset($usageList[$name])) {
|
|
|
|
|
foreach ($usageList[$name] as $user) {
|
|
|
|
|