diff --git a/src/Composer/DependencyResolver/SolverProblemsException.php b/src/Composer/DependencyResolver/SolverProblemsException.php index 0fa3b44b7..128fbe146 100644 --- a/src/Composer/DependencyResolver/SolverProblemsException.php +++ b/src/Composer/DependencyResolver/SolverProblemsException.php @@ -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 for more details.\n - It's a private package and you forgot to add a custom repository to find it\n\nRead 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); } } diff --git a/tests/Composer/Test/Fixtures/installer/platform-ext-solver-problems.test b/tests/Composer/Test/Fixtures/installer/platform-ext-solver-problems.test index 3e58bb2f2..aea9122b8 100644 --- a/tests/Composer/Test/Fixtures/installer/platform-ext-solver-problems.test +++ b/tests/Composer/Test/Fixtures/installer/platform-ext-solver-problems.test @@ -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-- diff --git a/tests/Composer/Test/Fixtures/installer/solver-problems-with-disabled-platform.test b/tests/Composer/Test/Fixtures/installer/solver-problems-with-disabled-platform.test index ce851a25a..9fab8e4cb 100644 --- a/tests/Composer/Test/Fixtures/installer/solver-problems-with-disabled-platform.test +++ b/tests/Composer/Test/Fixtures/installer/solver-problems-with-disabled-platform.test @@ -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-- diff --git a/tests/Composer/Test/Fixtures/installer/solver-problems.test b/tests/Composer/Test/Fixtures/installer/solver-problems.test index 240da2de8..66d10f1ef 100644 --- a/tests/Composer/Test/Fixtures/installer/solver-problems.test +++ b/tests/Composer/Test/Fixtures/installer/solver-problems.test @@ -156,6 +156,7 @@ Read 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.