Clean up a little to make impl less invasive and to handle replacers/providers
parent
23cae5939c
commit
6869a1a5cb
|
@ -22,6 +22,7 @@ use Composer\Package\Version\VersionParser;
|
||||||
use Composer\Package\Version\VersionSelector;
|
use Composer\Package\Version\VersionSelector;
|
||||||
use Composer\Plugin\CommandEvent;
|
use Composer\Plugin\CommandEvent;
|
||||||
use Composer\Plugin\PluginEvents;
|
use Composer\Plugin\PluginEvents;
|
||||||
|
use Composer\Repository\InstalledArrayRepository;
|
||||||
use Composer\Repository\ComposerRepository;
|
use Composer\Repository\ComposerRepository;
|
||||||
use Composer\Repository\CompositeRepository;
|
use Composer\Repository\CompositeRepository;
|
||||||
use Composer\Repository\PlatformRepository;
|
use Composer\Repository\PlatformRepository;
|
||||||
|
@ -196,17 +197,18 @@ EOT
|
||||||
$installedRepo = new InstalledRepository(array($lockedRepo));
|
$installedRepo = new InstalledRepository(array($lockedRepo));
|
||||||
$repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories()));
|
$repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories()));
|
||||||
} else {
|
} else {
|
||||||
$repos = $installedRepo = new InstalledRepository(array($this->getComposer()->getRepositoryManager()->getLocalRepository()));
|
// --installed / default case
|
||||||
$root = $composer->getPackage();
|
if (!$composer) {
|
||||||
$repo = $composer->getRepositoryManager()->getLocalRepository();
|
$composer = $this->getComposer();
|
||||||
|
}
|
||||||
|
$rootPkg = $composer->getPackage();
|
||||||
|
$repos = $installedRepo = new InstalledRepository(array($composer->getRepositoryManager()->getLocalRepository()));
|
||||||
|
|
||||||
if ($input->getOption('no-dev')) {
|
if ($input->getOption('no-dev')) {
|
||||||
$packages = $this->filterRequiredPackages($repo, $root);
|
$packages = $this->filterRequiredPackages($installedRepo, $rootPkg);
|
||||||
} else {
|
$repos = $installedRepo = new InstalledRepository(array(new InstalledArrayRepository(array_map(function ($pkg) { return clone $pkg; }, $packages))));
|
||||||
$packages = $this->appendPackages($repo->getPackages(), array());
|
|
||||||
}
|
}
|
||||||
$packageNames = array_keys($packages);
|
|
||||||
$rootPkg = $this->getComposer()->getPackage();
|
|
||||||
if (!$installedRepo->getPackages() && ($rootPkg->getRequires() || $rootPkg->getDevRequires())) {
|
if (!$installedRepo->getPackages() && ($rootPkg->getRequires() || $rootPkg->getDevRequires())) {
|
||||||
$io->writeError('<warning>No dependencies installed. Try running composer install or update.</warning>');
|
$io->writeError('<warning>No dependencies installed. Try running composer install or update.</warning>');
|
||||||
}
|
}
|
||||||
|
@ -358,13 +360,7 @@ EOT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$root = $composer->getPackage();
|
foreach ($repo->getPackages() as $package) {
|
||||||
if ($input->getOption('no-dev')) {
|
|
||||||
$packageList = $this->filterRequiredPackages($repo, $root);
|
|
||||||
} else {
|
|
||||||
$packageList = $this->appendPackages($repo->getPackages(), array());
|
|
||||||
}
|
|
||||||
foreach ($packageList as $package) {
|
|
||||||
if (!isset($packages[$type][$package->getName()])
|
if (!isset($packages[$type][$package->getName()])
|
||||||
|| !is_object($packages[$type][$package->getName()])
|
|| !is_object($packages[$type][$package->getName()])
|
||||||
|| version_compare($packages[$type][$package->getName()]->getVersion(), $package->getVersion(), '<')
|
|| version_compare($packages[$type][$package->getName()]->getVersion(), $package->getVersion(), '<')
|
||||||
|
@ -1239,6 +1235,7 @@ EOT
|
||||||
|
|
||||||
return $this->repositorySet;
|
return $this->repositorySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find package requires and child requires
|
* Find package requires and child requires
|
||||||
*
|
*
|
||||||
|
@ -1249,36 +1246,18 @@ EOT
|
||||||
*/
|
*/
|
||||||
private function filterRequiredPackages(RepositoryInterface $repo, PackageInterface $package, $bucket = array())
|
private function filterRequiredPackages(RepositoryInterface $repo, PackageInterface $package, $bucket = array())
|
||||||
{
|
{
|
||||||
$requires = array_keys($package->getRequires());
|
$requires = $package->getRequires();
|
||||||
|
|
||||||
$packageListNames = array_keys($bucket);
|
foreach ($repo->getPackages() as $candidate) {
|
||||||
$packages = array_filter(
|
foreach ($candidate->getNames() as $name) {
|
||||||
$repo->getPackages(),
|
if (isset($requires[$name])) {
|
||||||
function ($package) use ($requires, $packageListNames) {
|
if (!in_array($candidate, $bucket, true)) {
|
||||||
return in_array($package->getName(), $requires, true) && ! in_array($package->getName(), $packageListNames, true);
|
$bucket[] = $candidate;
|
||||||
|
$bucket = $this->filterRequiredPackages($repo, $candidate, $bucket);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
|
||||||
$bucket = $this->appendPackages($packages, $bucket);
|
|
||||||
|
|
||||||
foreach ($packages as $requiredPackage) {
|
|
||||||
$bucket = $this->filterRequiredPackages($repo, $requiredPackage, $bucket);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $bucket;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds packages to the package list
|
|
||||||
*
|
|
||||||
* @param array $packages the list of packages to add
|
|
||||||
* @param array $bucket the list to add packages to
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function appendPackages(array $packages, array $bucket)
|
|
||||||
{
|
|
||||||
foreach ($packages as $package) {
|
|
||||||
$bucket[$package->getName()] = $package;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $bucket;
|
return $bucket;
|
||||||
|
|
Loading…
Reference in New Issue