Refactor sortPackageMap to depend on separate sortPackage function.
parent
a908e22a91
commit
266a41e046
|
@ -17,6 +17,7 @@ use Composer\EventDispatcher\EventDispatcher;
|
||||||
use Composer\Installer\InstallationManager;
|
use Composer\Installer\InstallationManager;
|
||||||
use Composer\IO\IOInterface;
|
use Composer\IO\IOInterface;
|
||||||
use Composer\Package\AliasPackage;
|
use Composer\Package\AliasPackage;
|
||||||
|
use Composer\Package\Link;
|
||||||
use Composer\Package\PackageInterface;
|
use Composer\Package\PackageInterface;
|
||||||
use Composer\Repository\InstalledRepositoryInterface;
|
use Composer\Repository\InstalledRepositoryInterface;
|
||||||
use Composer\Util\Filesystem;
|
use Composer\Util\Filesystem;
|
||||||
|
@ -956,27 +957,18 @@ INITIALIZER;
|
||||||
*
|
*
|
||||||
* Packages of equal weight retain the original order
|
* Packages of equal weight retain the original order
|
||||||
*
|
*
|
||||||
* @param array $packageMap
|
* @param array $packages
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function sortPackageMap(array $packageMap)
|
public function sortPackages(array $packages) {
|
||||||
{
|
|
||||||
$packages = array();
|
|
||||||
$paths = array();
|
|
||||||
$usageList = array();
|
$usageList = array();
|
||||||
|
|
||||||
foreach ($packageMap as $item) {
|
foreach ($packages as $package) { /** @var PackageInterface $package */
|
||||||
list($package, $path) = $item;
|
foreach (array_merge($package->getRequires(), $package->getDevRequires()) as $link) { /** @var Link $link */
|
||||||
$name = $package->getName();
|
|
||||||
$packages[$name] = $package;
|
|
||||||
$paths[$name] = $path;
|
|
||||||
|
|
||||||
foreach (array_merge($package->getRequires(), $package->getDevRequires()) as $link) {
|
|
||||||
$target = $link->getTarget();
|
$target = $link->getTarget();
|
||||||
$usageList[$target][] = $name;
|
$usageList[$target][] = $package->getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$computing = array();
|
$computing = array();
|
||||||
$computed = array();
|
$computed = array();
|
||||||
$computeImportance = function ($name) use (&$computeImportance, &$computing, &$computed, $usageList) {
|
$computeImportance = function ($name) use (&$computeImportance, &$computing, &$computed, $usageList) {
|
||||||
|
@ -1034,9 +1026,41 @@ INITIALIZER;
|
||||||
|
|
||||||
$stable_sort($weightList);
|
$stable_sort($weightList);
|
||||||
|
|
||||||
$sortedPackageMap = array();
|
$sortedPackages = array();
|
||||||
|
|
||||||
foreach (array_keys($weightList) as $name) {
|
foreach (array_keys($weightList) as $name) {
|
||||||
|
$sortedPackages[] = $packages[$name];
|
||||||
|
}
|
||||||
|
return $sortedPackages;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sorts packages by dependency weight
|
||||||
|
*
|
||||||
|
* Packages of equal weight retain the original order
|
||||||
|
*
|
||||||
|
* @param array $packageMap
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function sortPackageMap(array $packageMap)
|
||||||
|
{
|
||||||
|
$packages = array();
|
||||||
|
$paths = array();
|
||||||
|
|
||||||
|
foreach ($packageMap as $item) {
|
||||||
|
list($package, $path) = $item;
|
||||||
|
$name = $package->getName();
|
||||||
|
$packages[$name] = $package;
|
||||||
|
$paths[$name] = $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sortedPackages = $this->sortPackages($packages);
|
||||||
|
|
||||||
|
|
||||||
|
$sortedPackageMap = array();
|
||||||
|
|
||||||
|
foreach ($sortedPackages as $package) {
|
||||||
|
$name = $package->getName();
|
||||||
$sortedPackageMap[] = array($packages[$name], $paths[$name]);
|
$sortedPackageMap[] = array($packages[$name], $paths[$name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -255,11 +255,8 @@ class PluginManager
|
||||||
{
|
{
|
||||||
$packages = $repo->getPackages();
|
$packages = $repo->getPackages();
|
||||||
$generator = $this->composer->getAutoloadGenerator();
|
$generator = $this->composer->getAutoloadGenerator();
|
||||||
$rootPackage = $this->composer->getPackage(); /** @var PackageInterface $rootPackage */
|
$sortedPackages = array_reverse($generator->sortPackages($packages));
|
||||||
$packageMap = $generator->buildPackageMap($this->composer->getInstallationManager(), $rootPackage, $packages);
|
foreach ($sortedPackages as $package) {
|
||||||
$sortedPackageMap = array_reverse($generator->sortPackageMap($packageMap));
|
|
||||||
foreach ($sortedPackageMap as $fullPackage) {
|
|
||||||
$package = $fullPackage[0]; /** @var PackageInterface $package */
|
|
||||||
if (!($package instanceof CompletePackage)) {
|
if (!($package instanceof CompletePackage)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Composer\Util;
|
||||||
|
|
||||||
|
|
||||||
|
class PackageSorter
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue