1
0
Fork 0

RepositorySet::findPackages now has an exactMatch option

Allows search for providers/replacers, or exact name search
pull/7625/head
Nils Adermann 2018-09-11 14:52:44 +02:00
parent 190d263c74
commit 7036f99999
3 changed files with 10 additions and 5 deletions

View File

@ -89,7 +89,7 @@ class BaseDependencyCommand extends BaseCommand
); );
// Find packages that are or provide the requested package first // 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)) { if (empty($packages)) {
throw new \InvalidArgumentException(sprintf('Could not find package "%s" in your project', $needle)); throw new \InvalidArgumentException(sprintf('Could not find package "%s" in your project', $needle));
} }

View File

@ -305,7 +305,7 @@ class PluginManager
*/ */
private function lookupInstalledPackage(RepositorySet $repositorySet, Link $link) 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; return !empty($packages) ? $packages[0] : null;
} }

View File

@ -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 ConstraintInterface|null $constraint
* @param bool $exactMatch
* @return array * @return array
*/ */
public function findPackages($name, ConstraintInterface $constraint = null) public function findPackages($name, ConstraintInterface $constraint = null, $exactMatch = true)
{ {
$packages = array(); $packages = array();
foreach ($this->repositories as $repository) { foreach ($this->repositories as $repository) {
@ -115,6 +116,10 @@ class RepositorySet
$result = array(); $result = array();
foreach ($candidates as $candidate) { foreach ($candidates as $candidate) {
if ($exactMatch && $candidate->getName() !== $name) {
continue;
}
if ($this->isPackageAcceptable($candidate->getNames(), $candidate->getStability())) { if ($this->isPackageAcceptable($candidate->getNames(), $candidate->getStability())) {
$result[] = $candidate; $result[] = $candidate;
} }