1
0
Fork 0

Better hint for missing extensions (#10283)

pull/9619/head
Shalvah 2021-11-26 10:39:07 +01:00 committed by GitHub
parent b9d7d27c82
commit 7a3d2b8157
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 11 deletions

View File

@ -47,16 +47,14 @@ class SolverProblemsException extends \RuntimeException
public function getPrettyString(RepositorySet $repositorySet, Request $request, Pool $pool, $isVerbose, $isDevExtraction = false)
{
$installedMap = $request->getPresentMap(true);
$hasExtensionProblems = false;
$missingExtensions = array();
$isCausedByLock = false;
$problems = array();
foreach ($this->problems as $problem) {
$problems[] = $problem->getPrettyString($repositorySet, $request, $pool, $isVerbose, $installedMap, $this->learnedPool)."\n";
if (!$hasExtensionProblems && $this->hasExtensionProblems($problem->getReasons())) {
$hasExtensionProblems = true;
}
$missingExtensions = array_merge($missingExtensions, $this->getExtensionProblems($problem->getReasons()));
$isCausedByLock = $isCausedByLock || $problem->isCausedByLock($repositorySet, $request, $pool);
}
@ -72,8 +70,8 @@ class SolverProblemsException extends \RuntimeException
$hints[] = "Potential causes:\n - A typo in the package name\n - The package is not available in a stable-enough version according to your minimum-stability setting\n see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.\n - It's a private package and you forgot to add a custom repository to find it\n\nRead <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.";
}
if ($hasExtensionProblems) {
$hints[] = $this->createExtensionHint();
if (!empty($missingExtensions)) {
$hints[] = $this->createExtensionHint($missingExtensions);
}
if ($isCausedByLock && !$isDevExtraction && !$request->getUpdateAllowTransitiveRootDependencies()) {
@ -106,9 +104,10 @@ class SolverProblemsException extends \RuntimeException
}
/**
* @param string[] $missingExtensions
* @return string
*/
private function createExtensionHint()
private function createExtensionHint(array $missingExtensions)
{
$paths = IniHelper::getAll();
@ -116,28 +115,34 @@ class SolverProblemsException extends \RuntimeException
return '';
}
$ignoreExtensionsArguments = implode(" ", array_map(function ($extension) {
return "--ignore-platform-req=$extension";
}, $missingExtensions));
$text = "To enable extensions, verify that they are enabled in your .ini files:\n - ";
$text .= implode("\n - ", $paths);
$text .= "\nYou can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.";
$text .= "\nAlternatively, you can run Composer with `$ignoreExtensionsArguments` to temporarily ignore these required extensions.";
return $text;
}
/**
* @param Rule[][] $reasonSets
* @return bool
* @return string[]
*/
private function hasExtensionProblems(array $reasonSets)
private function getExtensionProblems(array $reasonSets)
{
$missingExtensions = array();
foreach ($reasonSets as $reasonSet) {
foreach ($reasonSet as $rule) {
$required = $rule->getRequiredPackage();
if (null !== $required && 0 === strpos($required, 'ext-')) {
return true;
$missingExtensions[$required] = 1;
}
}
}
return false;
return array_keys($missingExtensions);
}
}

View File

@ -52,5 +52,6 @@ Your requirements could not be resolved to an installable set of packages.
To enable extensions, verify that they are enabled in your .ini files:
__inilist__
You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with `--ignore-platform-req=ext-filter` to temporarily ignore these required extensions.
--EXPECT--

View File

@ -81,6 +81,7 @@ Your requirements could not be resolved to an installable set of packages.
To enable extensions, verify that they are enabled in your .ini files:
__inilist__
You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with `--ignore-platform-req=ext-foobar --ignore-platform-req=ext-pcre --ignore-platform-req=ext-foobar --ignore-platform-req=ext-pcre` to temporarily ignore these required extensions.
--EXPECT--

View File

@ -156,6 +156,7 @@ Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further commo
To enable extensions, verify that they are enabled in your .ini files:
__inilist__
You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with `--ignore-platform-req=ext-xml` to temporarily ignore these required extensions.
Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.