Browse Source

RepositorySet::findPackages now has an exactMatch option

Allows search for providers/replacers, or exact name search
Nils Adermann 6 years ago
parent
commit
7036f99999

+ 1 - 1
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));
         }

+ 1 - 1
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;
     }

+ 8 - 3
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;
             }