1
0
Fork 0

Suggest which providers could be required to fulfill a virtual package requirement, fixes #2811

pull/8558/head
Jordi Boggiano 2020-01-30 09:23:20 +01:00
parent 3fc7e10c5c
commit 29efc473a1
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
3 changed files with 41 additions and 0 deletions

View File

@ -250,6 +250,17 @@ class Problem
return array("- Root composer.json requires $packageName, it ", 'could not be found, it looks like its name is invalid, "'.$illegalChars.'" is not allowed in package names.'); return array("- Root composer.json requires $packageName, it ", 'could not be found, it looks like its name is invalid, "'.$illegalChars.'" is not allowed in package names.');
} }
if ($providers = $repositorySet->getProviders($packageName)) {
$maxProviders = 20;
$providersStr = implode(array_map(function ($p) {
return " - ${p['name']} ".substr($p['description'], 0, 100)."\n";
}, count($providers) > $maxProviders+1 ? array_slice($providers, 0, $maxProviders) : $providers));
if (count($providers) > $maxProviders+1) {
$providersStr .= ' ... and '.(count($providers)-$maxProviders).' more.'."\n";
}
return array("- Root composer.json requires $packageName".self::constraintToText($constraint).", it ", "could not be found in any version, but the following packages provide it: \n".$providersStr." Consider requiring one of these to satisfy the $packageName requirement.");
}
return array("- Root composer.json requires $packageName, it ", "could not be found in any version, there may be a typo in the package name."); return array("- Root composer.json requires $packageName, it ", "could not be found in any version, there may be a typo in the package name.");
} }

View File

@ -52,6 +52,8 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
protected $cache; protected $cache;
protected $notifyUrl; protected $notifyUrl;
protected $searchUrl; protected $searchUrl;
/** @var string|null a URL containing %package% which can be queried to get providers of a given name */
protected $providersApiUrl;
protected $hasProviders = false; protected $hasProviders = false;
protected $providersUrl; protected $providersUrl;
protected $availablePackages; protected $availablePackages;
@ -416,6 +418,17 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
return parent::search($query, $mode); return parent::search($query, $mode);
} }
public function getProviders($packageName)
{
if (!$this->providersApiUrl) {
return array();
}
$result = $this->httpDownloader->get(str_replace('%package%', $packageName, $this->providersApiUrl), $this->options)->decodeJson();
return $result['providers'];
}
private function getProviderNames() private function getProviderNames()
{ {
$this->loadRootServerFile(); $this->loadRootServerFile();
@ -810,6 +823,10 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
$this->hasProviders = true; $this->hasProviders = true;
} }
if (!empty($data['providers-api'])) {
$this->providersApiUrl = $data['providers-api'];
}
return $this->rootData = $data; return $this->rootData = $data;
} }

View File

@ -158,6 +158,19 @@ class RepositorySet
return $candidates; return $candidates;
} }
public function getProviders($packageName)
{
foreach ($this->repositories as $repository) {
if ($repository instanceof ComposerRepository) {
if ($providers = $repository->getProviders($packageName)) {
return $providers;
}
}
}
return array();
}
public function isPackageAcceptable($names, $stability) public function isPackageAcceptable($names, $stability)
{ {
return StabilityFilter::isPackageAcceptable($this->acceptableStabilities, $this->stabilityFlags, $names, $stability); return StabilityFilter::isPackageAcceptable($this->acceptableStabilities, $this->stabilityFlags, $names, $stability);