123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- /*
- * This file is part of Composer.
- *
- * (c) Nils Adermann <naderman@naderman.de>
- * Jordi Boggiano <j.boggiano@seld.be>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Composer\DependencyResolver;
- use Composer\Util\IniHelper;
- use Composer\Repository\RepositorySet;
- /**
- * @author Nils Adermann <naderman@naderman.de>
- */
- class SolverProblemsException extends \RuntimeException
- {
- protected $problems;
- protected $learnedPool;
- public function __construct(array $problems, array $learnedPool)
- {
- $this->problems = $problems;
- $this->learnedPool = $learnedPool;
- parent::__construct('Failed resolving dependencies with '.count($problems).' problems, call getPrettyString to get formatted details', 2);
- }
- public function getPrettyString(RepositorySet $repositorySet, Request $request, Pool $pool)
- {
- $installedMap = $request->getPresentMap(true);
- $text = "\n";
- $hasExtensionProblems = false;
- foreach ($this->problems as $i => $problem) {
- $text .= " Problem ".($i + 1).$problem->getPrettyString($repositorySet, $request, $pool, $installedMap, $this->learnedPool)."\n";
- if (!$hasExtensionProblems && $this->hasExtensionProblems($problem->getReasons())) {
- $hasExtensionProblems = true;
- }
- }
- if (strpos($text, 'could not be found') || strpos($text, 'no matching package found')) {
- $text .= "\nPotential 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) {
- $text .= $this->createExtensionHint();
- }
- return $text;
- }
- public function getProblems()
- {
- return $this->problems;
- }
- private function createExtensionHint()
- {
- $paths = IniHelper::getAll();
- if (count($paths) === 1 && empty($paths[0])) {
- return '';
- }
- $text = "\n To enable extensions, verify that they are enabled in your .ini files:\n - ";
- $text .= implode("\n - ", $paths);
- $text .= "\n You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.";
- return $text;
- }
- private function hasExtensionProblems(array $reasonSets)
- {
- foreach ($reasonSets as $reasonSet) {
- foreach ($reasonSet as $rule) {
- if (0 === strpos($rule->getRequiredPackage(), 'ext-')) {
- return true;
- }
- }
- }
- return false;
- }
- }
|