From 7036f999990a4a2ec394cf0fb0506f860ecdd19b Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 11 Sep 2018 14:52:44 +0200 Subject: [PATCH] RepositorySet::findPackages now has an exactMatch option Allows search for providers/replacers, or exact name search --- src/Composer/Command/BaseDependencyCommand.php | 2 +- src/Composer/Plugin/PluginManager.php | 2 +- src/Composer/Repository/RepositorySet.php | 11 ++++++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Composer/Command/BaseDependencyCommand.php b/src/Composer/Command/BaseDependencyCommand.php index ca80fa246..b2b617c42 100644 --- a/src/Composer/Command/BaseDependencyCommand.php +++ b/src/Composer/Command/BaseDependencyCommand.php @@ -89,7 +89,7 @@ class BaseDependencyCommand extends BaseCommand ); // Find packages that are or provide the requested package first - $packages = $repositorySet->findPackages(strtolower($needle)); // TODO this does not search providers + $packages = $repositorySet->findPackages(strtolower($needle), null, false); if (empty($packages)) { throw new \InvalidArgumentException(sprintf('Could not find package "%s" in your project', $needle)); } diff --git a/src/Composer/Plugin/PluginManager.php b/src/Composer/Plugin/PluginManager.php index d16c51db1..786d846c5 100644 --- a/src/Composer/Plugin/PluginManager.php +++ b/src/Composer/Plugin/PluginManager.php @@ -305,7 +305,7 @@ class PluginManager */ private function lookupInstalledPackage(RepositorySet $repositorySet, Link $link) { - $packages = $repositorySet->findPackages($link->getTarget(), $link->getConstraint()); // TODO this no longer returns providers + $packages = $repositorySet->findPackages($link->getTarget(), $link->getConstraint(), false); return !empty($packages) ? $packages[0] : null; } diff --git a/src/Composer/Repository/RepositorySet.php b/src/Composer/Repository/RepositorySet.php index d3c652ccb..f83de3b14 100644 --- a/src/Composer/Repository/RepositorySet.php +++ b/src/Composer/Repository/RepositorySet.php @@ -98,13 +98,14 @@ class RepositorySet } /** - * Find packages matching name and optionally a constraint in all repositories + * Find packages providing or matching a name and optionally meeting a constraint in all repositories * - * @param $name + * @param string $name * @param ConstraintInterface|null $constraint + * @param bool $exactMatch * @return array */ - public function findPackages($name, ConstraintInterface $constraint = null) + public function findPackages($name, ConstraintInterface $constraint = null, $exactMatch = true) { $packages = array(); foreach ($this->repositories as $repository) { @@ -115,6 +116,10 @@ class RepositorySet $result = array(); foreach ($candidates as $candidate) { + if ($exactMatch && $candidate->getName() !== $name) { + continue; + } + if ($this->isPackageAcceptable($candidate->getNames(), $candidate->getStability())) { $result[] = $candidate; }